【发布时间】:2010-08-09 08:54:21
【问题描述】:
我还是 Ruby on Rails 的新手,目前遇到路由和重定向问题。
我有两个控制器“候选人”和“调查”。我目前正在查看“canidate/editEmail.html”
http://www.otoplusvn.com/TherapistSurvey/candidates/editEmail/2
一旦点击提交按钮,就会执行候选人更新邮件的方法:
def updateEmail
@candidate = Candidate.find(params[:id])
respond_to do |format|
if @candidate.update_attributes(params[:candidate])
flash[:notice] = 'Candidate email was successfully updated.'
format.html { redirect_to :controller => "survey", :action => "end" }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @candidate.errors, :status => :unprocessable_entity }
end
end
end
此代码将更新数据库中候选人的电子邮件并将其重定向。我想将它重定向到位于 view/Survey/end.html.erb 下的名为 end.html.erb 的 html 页面。但是,使用目前的代码,它会给我一个
Unknown action
No action responded to show. Actions: download and lastPage
其中 download 和 lastPage 是 Survey 控制器中的唯一方法。 “end”不是survey_controller.rb中定义的方法,但我认为它会自动跳转到位于views/survey下的end.html.erb
在我的本地机器上,我可以让它与这个更新的代码一起工作:
format.html { redirect_to :controller => "survey/end" }
但这在我加载 ruby on rail 应用程序的网站上不起作用。无论哪种情况,我认为可能有一种更简单的方法可以做到这一点,但我做错了。
当您将本地 ruby on rail 应用程序移植到主机时,我认为它必须处理我不知道的 route.rb 文件或权限。
通常我会认为如果我直接进入文件
http://www.otoplusvn.com/TherapistSurvey/survey/end
我可以像在本地计算机上一样查看该页面,但我无法使用我托管的内容。
一般来说,我只是希望能够重定向(跳转)到另一个 html 页面,表明电子邮件更新已正确完成并且调查已结束。这一切都是通过点击提交按钮触发的,该按钮导致对数据库的更新被称为重定向到另一个页面。问题是如何正确进行重定向。
顺便说一句:在我的 routes.rb 我有
map.resources :survey
任何建议表示赞赏。谢谢! D
【问题讨论】:
标签: ruby-on-rails redirect routing