0

I have static pages in my app. This app is running on two different domains.

I want some of the static pages to show <%=@domain%> name. All the contents are static but only the domain name is dynamic. How can I get this done in rails?

like

cache do
 some content goes here and then i want to display the <%=request.domain()%>
end

With the above way: request.domain() will cached first and will be served with the same domain name ignoring which domain you are using to access this later.

Mike Szyndel
  • 10,461
  • 10
  • 47
  • 63
kashif
  • 1,097
  • 4
  • 17
  • 32
  • [Maybe this question will be of help](http://stackoverflow.com/questions/2165665/how-do-i-get-the-current-url-in-ruby-on-rails) – Althaf Hameez Jul 15 '13 at 06:16
  • no man. this is not to get the current URL. say if i get the current url and gets this url cached first time, it will be same url for all users visiting the site. its about caching + dynamic host name – kashif Jul 15 '13 at 06:26
  • By static you mean this is in `public/` dir? – Mike Szyndel Jul 15 '13 at 07:38
  • Why don't you generate the file on deploy / startup? I mean the domain will not change during runtime. Either do it in your capistrano deploy.rb or add an initializer that generates the file. – ayckoster Jul 15 '13 at 08:42

2 Answers2

0

in your view:

<%= request.domain() %>

on my local machine app that runs on localhost:3000 the above code returns localhost on the screen.

cache "first_part_up_to_domain_name" do
 some content goes here and then i want to display the 
end

<%=request.domain()%>

cache "the_rest_after_domain_name" do
 rest of the content
end

in other cases with dynamic pages you could use expire cache method to overwrite the cached pages, but with static pages not sure how you can do this.

rmagnum2002
  • 11,341
  • 8
  • 49
  • 86
  • may be I've not explained it well. let me explain it again 'cache do some static content goes here and i also want to display <%=request.domain()%> end' with the above way: request.domain() will cached first and will be served with the same domain name ignoring which domain you are using to access this – kashif Jul 15 '13 at 07:02
  • may be :) I understood that you want the domain name to appear on your page. – rmagnum2002 Jul 15 '13 at 07:04
  • i just modified the question to help better understanding. – kashif Jul 15 '13 at 07:10
  • do you cache all the pages? where do you show the domain name? may be you better cache your content up to the domain name, and start another cache frame after the domain name so the `<%= request.domain %>` stays out of cache – rmagnum2002 Jul 15 '13 at 07:13
  • well. I found a solution which seems simple and easy. I added a key to caching and that will create two different keys for each domain and when a user will visit a domain on the basis of key it will pick up the cached contents. Thanks all for your feedback. cache("#{@page_title}_#{request.domain()}") some static text goes here <%=request.domain()%> end – kashif Jul 15 '13 at 08:33
0

well. I found a solution which seems simple and easy. I added a key to caching and that will create two different keys for each domain and when a user will visit a domain on the basis of key it will pick up the cached contents. Thanks all for your feedback.

 cache("#{@page_title}_#{request.domain()}") 
   some static text goes here <%=request.domain()%> 
 end
kashif
  • 1,097
  • 4
  • 17
  • 32