将值设置为创建时的参数

时间:2017-08-03 05:24:36

标签: ruby-on-rails

根据订单尝试进行不同的订单,迁移文件中有一个不同的revisions_left

我通过params[:orderref]这样的按钮传递<%= link_to 'Package 1', new_order_path(orderref: 1)%>,然后尝试用create方法调用它

if params[:orderref] == "1"
  @order.revisions_left = 1
elsif params[:orderref] == "2"
  @order.revisions_left = 2
elsif params[:orderref] == "3"
  @order.revisions_left = 3
end

revisions_left无法保存,我不确定为什么

修改:记录

&#13;
&#13;
Processing by OrderController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"VGt/2PCPMmVnzXGm+UgHcmSvX7FEHxOoF/TfJoKf8gn3NJ0grD9JkydfswwV50GXIneFuTSClLK7cqvpsRCwRg==", "order"=>{"name"=>"sdada", "email"=>"as@tt.com", "company"=>"", "event_type"=>"Birthday", "country"=>"Brazil", "description"=>"1233 1 123 11", "order_type"=>"3", "price"=>"80"}, "commit"=>"Create Order"}
  Order Load (3.0ms)  SELECT  "orders".* FROM "orders" WHERE "orders"."name" = $1 AND "orders"."company" = $2 AND "orders"."email" = $3 AND "orders"."event_type" = $4 AND "orders"."country" = $5 AND "orders"."description" = $6 AND "orders"."order_type" = $7 AND "orders"."price" = $8 ORDER BY "orders"."id" ASC LIMIT $9  [["name", "sdada"], ["company", ""], ["email", "as@tt.com"], ["event_type", "Birthday"], ["country", "Brazil"], ["description", "1233 1 123 11"], ["order_type", 3], ["price", 80], ["LIMIT", 1]]
   (0.4ms)  BEGIN
  Order Exists (1.0ms)  SELECT  1 AS one FROM "orders" WHERE LOWER("orders"."email") = LOWER($1) LIMIT $2  [["email", "as@tt.com"], ["LIMIT", 1]]
  SQL (6.2ms)  INSERT INTO "orders" ("name", "company", "email", "event_type", "country", "description", "price", "order_type", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"  [["name", "sdada"], ["company", ""], ["email", "as@tt.com"], ["event_type", "Birthday"], ["country", "Brazil"], ["description", "1233 1 123 11"], ["price", 80], ["order_type", 3], ["created_at", 2017-08-03 05:26:21 UTC], ["updated_at", 2017-08-03 05:26:21 UTC]]
   (71.2ms)  COMMIT
   (0.1ms)  BEGIN
  Order Exists (0.5ms)  SELECT  1 AS one FROM "orders" WHERE LOWER("orders"."email") = LOWER($1) AND ("orders"."id" != $2) LIMIT $3  [["email", "as@tt.com"], ["id", 3], ["LIMIT", 1]]
  SQL (0.7ms)  UPDATE "orders" SET "status" = $1, "updated_at" = $2 WHERE "orders"."id" = $3  [["status", 1], ["updated_at", 2017-08-03 05:26:22 UTC], ["id", 3]]
   (0.3ms)  COMMIT
&#13;
&#13;
&#13;

0 个答案:

没有答案