【发布时间】:2020-07-28 19:44:06
【问题描述】:
我需要放一个蓝色按钮来复制并保存具有相同信息的新对象,只需复制该行即可。
我尝试以下操作,但是当我单击蓝色按钮时,只需转到该行的显示 我不知道我错过了什么(也许很多)
gastos.html.erb
<button type="button" class="btn btn-sm btn-primary mr-2 command-delete">
<%= link_to '', gasto, action: dup, class: "fa fa-trash fa-fw text-light" %>
</button>
gastos_controller.rb
def dup
@gasto_dup = Gasto.find(params[:id]).dup
render :new
end
点击蓝色按钮时的日志
Started GET "/gastos/152" for 127.0.0.1 at 2020-07-28 16:03:57 -0400
Processing by GastosController#show as HTML
Parameters: {"id"=>"152"}
User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Gasto Load (1.5ms) SELECT "gastos".* FROM "gastos" WHERE "gastos"."id" = $1 LIMIT $2 [["id", 152], ["LIMIT", 1]]
↳ app/controllers/gastos_controller.rb:135:in `set_gasto'
Rendering gastos/show.html.erb within layouts/application
Rendered gastos/show.html.erb within layouts/application (Duration: 2.9ms | Allocations: 91)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 133ms (Views: 102.7ms | ActiveRecord: 2.4ms | Allocations: 17541)
【问题讨论】:
-
共享服务器的日志,我认为请求将发送到其他控制器
标签: ruby-on-rails ruby postgresql