【发布时间】:2016-02-24 07:04:09
【问题描述】:
单击每个按钮时,我想将properties 表中的status 值更新为(1 或2 或3 或4)。
这些是我的视图文件中的按钮:
<td><%= link_to("Waiting for Response", rms_property_approve_property_path(property, {:status => 'Waiting for Response'}), method: :patch, class: "btn btn-success", "data-no-turbolink" => true) %><td>
<td><%= link_to("No Response", rms_property_approve_property_path(property, {:status => 'No Response'}), method: :patch, class: "btn btn-danger", "data-no-turbolink" => true) %><td>
<td><%= link_to("Registered", rms_property_approve_property_path(property, {:status => 'Registered'}), method: :patch, class: "btn btn-success", "data-no-turbolink" => true) %><td>
<td><%= link_to("Not Interested", rms_property_approve_property_path(property, {:status => 'Not Interested'}), method: :patch, class: "btn btn-danger", "data-no-turbolink" => true) %><td>
我的properties_controller.rb:
def approve
@property = Property.find(params[:property_id])
if params[:status]== 'Registered'
@property.update_attributes(:status => 1)
redirect_to :back, flash: {notice: "Property has been Registered."}
elsif params[:status]== 'Not Interested'
@property.update_attributes(:status => 2)
redirect_to :back, flash: {notice: "Not Interested."}
elsif params[:status]== 'Waiting for Response'
@property.update_attributes(:status => 3)
redirect_to :back, flash: {notice: "Waiting for Response"}
elsif params[:status]== 'No Response'
@property.update_attributes(:status => 4)
redirect_to :back, flash: {notice: "No Response."}
end
end
properties 表中状态列的迁移文件:
class AddColumnStatusInProperties < ActiveRecord::Migration
def change
add_column :properties, :status, :string
end
end
当我点击 No response 按钮时,我得到一个 ArgumentError:
'4' is not a valid status
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 activerecord