【问题标题】:best_in_place - Have to Refresh Page to Show Changesbest_in_place - 必须刷新页面才能显示更改
【发布时间】: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


    【解决方案1】:

    不太确定我是如何修复它的,但它可以正常工作。这就是我所做的。

    我将更新操作更改为

    respond_to :html, :json
    
    
    def update
    
        @variation = Variation.find(params[:id])
        @variation.update_attributes(variation_params)
        respond_with(@variations)
    end
    

    所有作品。

    更新:best_in_place 在下面使用 json,但控制器没有正确响应 json。因此,通过添加 respond_to 和 respond_with 它可以正常工作。

    【讨论】:

      猜你喜欢
      • 2013-08-19
      • 1970-01-01
      • 2021-09-24
      • 1970-01-01
      • 2013-06-02
      • 2023-03-09
      • 2020-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多