【发布时间】:2016-07-13 19:48:04
【问题描述】:
我将茧用于嵌套表单。因此,当我添加一个实验时,我可以通过同一个表单添加所有变化。我安装了gem 'best_in_place', '~> 3.1' 以使编辑更容易,但更新后我遇到了问题。
通过 best_in_place 助手,我可以单击描述并进行更改。数据库已更新,更改会显示片刻,然后消失,回到我更改之前的状态。如果我刷新页面,我的更改是可见的。因此需要刷新页面才能显示更改。
我无法让 best_in_place 正常工作,在阅读后,我最终在嵌套路线之外粘贴了一条路线以使其正常工作
routes.rb
resources :advertisers do
resources :experiments do
resources :variations
end
end
resources :variations, only: [:update, :show]
我在 experiments show.html.erb 文件中使用 best_in_place
<% @experiment.variations.each do |variation| %>
<h3><i class="fa fa-square"></i> <%= variation.name %></h3>
<p class="data-row">
<span class="data-name">URL</span>
<span class="data-value"><%= variation.url %></span>
</p>
<p class="data-row">
<span class="data-name">Description</span>
<div><%= best_in_place variation, :description, :as => :textarea %></div>
</p>
<% end %>
我认为问题出在我的变体更新操作中。这是我的变体控制器
class VariationsController < ApplicationController
before_action :find_variation
def update
@variation.update(variation_params)
end
private
def variation_params
params.require(:variation).permit(:description, :name, :url)
end
def find_variation
@variation = Variation.find(params[:id])
end
end
任何帮助将不胜感激!
【问题讨论】:
标签: ruby-on-rails view best-in-place