0

I can't update field in database table. Why, when I working in edit template(controller/id/edit), rails redirect me to CREATE action and create a new row in table? It must redirect me to update action and update only one field. Controller:

  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

edit template

= 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"
4

1 回答 1

0

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

你应该有你的表格:

= form_for Question do |w|
于 2013-06-02T17:53:00.720 回答