Ruby on rails Rails-当我在多个页面上有一个用户表单时,如何重定向到不同的页面?
我试图让用户在注册、问卷页面、仪表板时遵循特定的路径,但我在试图让问卷页面关注自己的业务时遇到了问题 控制器的相关位:Ruby on rails Rails-当我在多个页面上有一个用户表单时,如何重定向到不同的页面?,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,我试图让用户在注册、问卷页面、仪表板时遵循特定的路径,但我在试图让问卷页面关注自己的业务时遇到了问题 控制器的相关位: def update @user = current_user if @user.save redirect_to :back flash[:notice] = "Updated!" else redirect_to :back flash[:notice] = "Couldn't save your info" end end def questi
def update
@user = current_user
if @user.save
redirect_to :back
flash[:notice] = "Updated!"
else
redirect_to :back
flash[:notice] = "Couldn't save your info"
end
end
def questionnaire
@user = current_user
if @user.update_attributes(params[:user]) # just informed this bit of code won't do anything
redirect_to user_dashboard_path
flash[:notice] = "Thanks for filling out the questionnaire."
else
redirect_to user_introduction_path
flash[:notice] = "Couldn't save."
end
end
以下是我在问卷页面上使用的视图:
=simple_form_for @user, :url => {:action => "about_yourself"} do |f|
%p What\'s your name?
=f.input :name, label: "Your name, please."
%p Gender?
=simple_fields_for :personal_detail do |p|
= p.input :gender, :collection => %w[Male Female]
%p Age?
=f.input :age
=f.submit "Let's rock"
当特定视图中的表单更新模型时,如何使表单重定向到特定页面?基本上,如果需要的话,可以从不同的页面使用不同重定向的更新方法。只是一个想法,但您必须清楚,当您提交表单以更新用户时,它将转到更新操作。在你的调查问卷操作中,if@user.update_attributesparams[:user]并没有真正完成任何事情。我想这是我的问题。。。我将重新表述我的问题,谢谢!我认为您可以在每个特定视图中添加一个隐藏输入,并使这些视图更新为一个控制器,然后为隐藏值设置条件以处理重定向目的。