我还是Ruby on Rails的新手,我目前遇到了路由和重定向的问题。重定向和路由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是调查控制器中唯一的方法。 “end”不是在survey_controller.rb中定义的方法,但我认为它会自动跳转到位于views/survey下的end.html.erb在我的本地机器上,我能够得到这个这个更新的代码工作:
format.html { redirect_to :controller => "survey/end" }
但这不是我装上轨应用的红宝石在现场工作。在任何一种情况下,我认为可能有一种更简单的方法来做到这一点,我做错了。
我认为它必须处理route.rb文件或许可证,当您将导航应用程序中的本地ruby移植到主机时,我并不知道这些文件或权限。
通常我会想,如果我直接去了文件
http://www.otoplusvn.com/TherapistSurvey/survey/end
我能看到的网页就像我能在我的本地机器上,但我不能用我托管的东西。
一般而言,我只是希望能够重定向(跳转)到另一个HTML页面,表明电子邮件更新已正确完成,并且调查已结束。这一切都是通过点击一个提交按钮触发的,这个按钮导致数据库更新被称为重定向到另一个页面。问题是如何正确执行重定向。
BTW:在我的routes.rb我有
map.resources :survey
知道的任何建议。谢谢! d
我加了它,但我仍然得到未知的动作。 我做了一个耙路径来显示路径。 PUT /candidates/:id(.:format){:controller =>“candidates”,:action =>“update”} DELETE /candidates/:id(.:format){:controller =>“candidates” ,:action =>“destroy”} end_survey GET /survey/end(.:format){:controller =>“survey”,:action =>“end”} – darewreck 2010-08-09 10:03:43
“end”实际上必须定义为行动还是把它作为一个end.html.erb足够的查看/调查? – darewreck 2010-08-09 10:08:46
我也更新了“end”到“lastPage”,所以它不会与关键词混淆,最终点击otoplusvn.com/TherapistSurvey/candidates/editEmail/2,你会得到一个页面otoplusvn.com/TherapistSurvey/survey/lastPage - – darewreck 2010-08-10 07:22:05