简体   繁体   中英

Rails redirecting to a subdomain with a notice message

I am redirecting the user to a subdomain of the application based on the parameter

respond_to do |format|
      format.html {  redirect_to home_url(subdomain: params[:company]), notice: "Couldn't able to process your request, please try after some time" }
end

with a notice message, and the html page to which i am redirecting the user looks like

<% flash.each do |name, msg| %>
    <%= content_tag :div, msg, class: "alerts alerts-info bodyLeftPadd" %>
<% end %>

for displaying the flash message.

But the problem here is the notice message is not displayed.

Is the use of subdomain causing this problem, because if remove the subdomain and if i redirect to the url within the same subdomain i could see the flash message being displayed.

 respond_to do |format|
          format.html {  redirect_to home_url, notice: "Couldn't able to process your request, please try after some time" }
 end

Flash messages are stored in your session, which is tied to a cookie. (If you're using cookie_store all session data is kept in the cookie, or if you're using active_record_session you have a session cookie which is tied to data in your database).

The problem is that cookies won't follow you across subdomains unless you've configured them to. See Share session (cookies) between subdomains in Rails?

It sounds like the critical part is to include domain: '.yourdomain.com' in the line where you configure your session store. From Action Controller Overview: Sessions :

Rails.application.config.session_store :cookie_store, key: '_your_app_session', domain: ".example.com"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM