restful controller忽略更新动作

时间:2013-06-02 17:43:31

标签: ruby-on-rails ruby routes haml restful-architecture

我无法更新数据库表中的字段。为什么,当我在编辑模板(controller / id / edit)中工作时,rails会将我重定向到CREATE操作并在表中创建一个新行?它必须将我重定向到更新操作并仅更新一个字段。 控制器:

  def create
 Question.create(:user_id => session[:user_id], :question => params[:question][:question])
 end

  def update
  debugger #not go there
  @update = Question.find(params[:id])
  @update.update_attributes(params[:question_status])
 end

编辑模板

= form_for Question.new do |w|
  %p
= w.label :question_status, :caption => "question status: "
= w.text_field :question_status
  %p
= w.submit "Update"

routs.rb

match "questions/logout" => "questions#logout"
match "questions/show_all_questions" => "questions#show_all_questions"
match "questions/update" => "questions#update"
resources :questions

get "questions/create" 
get "questions/show"
get "questions/update"
get "questions/destroy"
get "questions/new"
get "questions/edit"
get "questions/index"

1 个答案:

答案 0 :(得分:0)

它将您重定向到create方法,因为您调用Question.new。

你的表格应该是:

= form_for Question do |w|