Bala Karthik Bala Karthik - 3 months ago 11
HTML Question

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" }

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" }


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: '' 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: ""