Rails rest in peace gem -如何在每个循环中使用

Rails rest in peace gem - how to use in each loop?

本文关键字:循环 in rest peace gem Rails      更新时间:2023-09-26

我正在使用其余的地方gem: https://github.com/janv/rest_in_place。

如何在每个循环中正确使用它?更具体地说,对于belongs_to关系?

例如:User has_many :fee_agreements和FeeAgreement belongs_to :user

如何利用就地编辑功能来更新此处的fee_agreement"loan_amount"?

<tbody>
<% @user.fee_agreements.each do |fa| %>
<tr>
  <td><%= fa.user_id %></td>
  <td><%= fa.loan_id %></td>
  <td id="<%=  dom_id(fa)  %>"><span class="rest-in-place" data-formtype="input" data-attribute="loan_amount"><%= fa.loan_amount %></span></td>
  #above is the line in question
</tr>
<% end %>
</tbody>
控制台输出

:

 Started PUT "/users/51" for 127.0.0.1 at 2014-03-19 00:19:29 -0400
 Processing by UsersController#update as JSON
 Parameters: {"authenticity_token"=>"xxx=", "fee_agreement"=>{"loan_amount"=>"998988"}, "id"=>"51"}

我确实有一个单独的控制器为FeeAgreements"构建"用户..

def create
  @fee_agreement = current_user.fee_agreements.build(:loan_id => params[:loan_id])
  if @fee_agreement.save
    redirect_to fee_agreements_path
  else
    redirect_to index_path
  end
end

试一试:

用Best in Place gem代替rest_in_place

在进行了一些初始设置之后,您可以通过

使用它
<tbody>
<% @user.fee_agreements.each do |fa| %>
<tr>
  <td><%= fa.user_id %></td>
  <td><%= fa.loan_id %></td>
  <td><%= beast_in_place fa.loan_amount %></span></td>
  #above is the line in question
</tr>
<% end %>
</tbody>