Show a modal right after signup?

本小妞迷上赌 提交于 2020-01-24 23:08:51

问题


When a user signup at my page I want them to be redirected to the root_path(this I have figured out how to do in the user controller). But then I want a modal to show in front of this page(and this should only happen the first time the user see this root/home page(like a flash message).

Here is my create method in the user controller:

def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      redirect_to root_path
    else
      render 'new'
    end
  end

The modal is placed in app/views/layouts/_modal.html.erb. Does anybody know how to make this happen?

(Jepp, I am a newbie :)


回答1:


You mentioned flash, and I thought it would be a good idea to take advantage of Rails' prebuilt flash usage to display your modal.

def create
  @user = User.new(params[:user])
  if @user.save
    sign_in @user
    session[:modal] = true
    redirect_to root_path
  else
    render 'new'
  end
end

In your view:

<% if session[:modal] == true %>
  <%= render :partial => 'layouts/modal'%>
<% end %>


来源:https://stackoverflow.com/questions/11285600/show-a-modal-right-after-signup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!