我试图让用户在注册时关注特定路径(注册,问卷调查页面,信息中心),但我遇到问题,试图让调查问卷页面记住它自己的事业。
控制器的相关位:
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"
当特定视图中的表单更新模型时,如何让表单重定向到特定页面?如果需要,基本上使用不同页面中的更新方法和不同的重定向。