4

Using Rails 3.0.3 in combination with gems like devise I don't get any flash messages. Now I mention devise, because it controls the cookies used to authenticate me.

Now the Rails application is a bit special since its using sub-domains. What they do is tell the application which company a user is browsing. An example: mycompany.theapp.com/projects/3/ <- Project 3 of company "mycompany".
When a user logs in he/she is directed to theapp.com/overview <- non subdomain
Every notice there does show, so why not on sub-domain pages?

So this is the code used on sub-domain pages. Exactly the same as one would put it on non-sub-domain pages. The code in the controller:

def update
  redirect_to [@project], :notice => "Project #{@project.name} updated."
end

The layouts/application.html.erb

<% flash.each do |type, message| %>
  <%= content_tag :div, message, :class => "flash #{type}" %>
<% end %>

I also added the following, trying to figure out what is happening:

flash.to_yaml
# Result: --- !map:ActionDispatch::Flash::FlashHash {} 

Since apparently devise uses flash[:notice] I also tried that (because that was working for devise).

flash[:notice] = "Project #{@project.name} updated."
# Result: --- !map:ActionDispatch::Flash::FlashHash {} 

Now do the notices get send by cookies or session data that isn't transferred well to sub-domains? Because the edit form of the project is on mycompany.theapp.com/projects/3/edit/
And it sends me to mycompany.theapp.com/projects/3/ (without notice)

It happens on Ubuntu 10.10 with "rails server", passenger using nginx and even on a Mac machine (but someone else tested that).

Anyone care to guess?

Charles
  • 50,943
  • 13
  • 104
  • 142
tombruijn
  • 1,130
  • 10
  • 13
  • Are you sure that when a user transfers to a subdomain they're still logged in? This isn't the default behavior (you have to explicitly allow cookies to cross subdomains). Maybe users aren't logged in and are being served views without flashes in the layout? – David Sulc Dec 15 '10 at 19:54

1 Answers1

6

Apparently there wasn't really something wrong with the configuration. We deployed it on a server real quick, production mode, and it worked, much to our surprise. The notices were showing up across all domains.
It's something with localhost domains, I was using lvh.me, that Rails doesn't quite get.

The hint was in a (recent) comment on a railscast:

http://railscasts.com/episodes/221-subdomains-in-rails-3?view=comments#comment_146276 There's one important thing to know if you want to share sessions between subdomains on localhost. Using :domain => ".lvh.me" not always works (in my case it didn't), so you have to configure your environment as described in blog.plataformatec.com.br/2009/12/subdomains-and-sessions-to-the-rescue/

@David Sulc, the users were logged in.

tombruijn
  • 1,130
  • 10
  • 13
  • +1. Thank you for linking the comment. Exactly what I was looking for. – Shreyas Mar 16 '11 at 10:36
  • i had a similar problem but that was a css issue, i did not have the flash message, flash error and form errors css code. but that's a year ago i think – Kees Sonnema Jul 06 '12 at 11:57