Question

so im studying ROR using rails 4 and im trying to verify the current domain in my app, and set custom messages for each domain.

I have something like this in my app/views/layouts/application.html.haml:

!!!
%html
  %head
    //verify the domain here
    //store in a var?
    %meta{ content: 'text/html; charset=utf-8', 'http-equiv' => 'Content-Type' }
    %meta{ content: 'Set the message according each domain here', name: 'description'}

Someone may help?

Was it helpful?

Solution

You can get the domain from the request object, which is available in views/controllers/helpers:

request.domain

Better practice us to set the messages in the controller action, and then just display them in the view, e.g.:

def my_action
  @domain_message = get_domain_message(request.domain)
end

def get_domain_message(domain)
  case domain
  when 'example.com' then 'domain specific message'
  when 'egzample.com' then 'another domain specific message'
  end
end

Now @domain_message is available for use in the view.

OTHER TIPS

You can define a hash like this:

messages = {"www.example.com" => "Message for www.example.com", "www.example2.com" => "Message for www.example2.com"}

now you can display message using this:

messages[request.host]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top