Rails 3 notifications

Using Rails 3.0.3 combined with the same skills as devise. I do not receive any flash messages. Now I mention devise because it controls the cookies used for authentication.

The Rails application is now a little special because it uses subdomains . What they do is the application that the user is viewing. Example: mycompany.theapp.com/projects/3/ <- Project 3 of the company "mycompany".
When a user logs in, he goes to aapp.com/overview <- non subdomain. Each notification is shown there, so why not on subdomain pages?

So this is the code used on subdomain pages. Just like on non-subdomain pages. Code in the controller:

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

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 was going on:

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

Since devise seems to use flash [: notice], I also tried this (because it worked for development).

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

Now, are notifications sent cookies or session data that is poorly transferred to subdomains? Since the project editing form is at mycompany.theapp.com/projects/3/edit/
And he sends me to mycompany.theapp.com/projects/3/( without notice)

This happens on Ubuntu 10.10 with a "rail server", a passenger using nginx, and even on a Mac machine (but someone else checked this out).

Does anyone want to guess?

+4
source share
1 answer

Apparently there was nothing wrong with the configuration. We deployed it to the server in real fast, production mode, and it worked, to our surprise. Notifications were shown in all domains.
This is something with localhost domains, I used lvh.me that Rails did not quite understand.

The tip was in a recent comment on railscast:

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

@David Sulc, users are logged in.

+6
source

Source: https://habr.com/ru/post/1332248/


All Articles