Rails - best_in_place直到重新加载后才更新视图

时间:2015-08-14 12:24:48

标签: ruby-on-rails ruby best-in-place

我是Ruby on Rails的新手,我正在与best_in_place进行斗争 我正在使用best_in_place来启用HTML表格中的数据编辑。我能够成功输入数据并按Enter键进行保存。新数据在表格中简要显示,但很快又恢复到之前的值。如果我重新加载页面,表格将显示新的更新数据。有没有人有任何建议如何立即显示更新的数据?

这是我的控制器的代码:

    class GamesController < ApplicationController
      def index
        @games = Game.all
      end

      def show
        @game = Game.find(params[:id])
        #render 'index'
      end

      def new
        @game = Game.new
      end

      def edit
        @game = Game.find(params[:id])
      end

      def create
        @game = Game.new(game_params)

        if @game.save
          redirect_to @game
        else
          render 'new'
        end
      end

      def update
        @game = Game.find(params[:id])

        if @game.update(game_params)
          redirect_to @game
        else
          render 'edit'
        end
      end

    def destroy
        @game = Game.find(params[:id])
          @game.destroy

            redirect_to games_path
            end

    private
      def game_params
        params.require(:game).permit(:number, :title, :weight, :owner, :borrower, :borrowed)
      end
    end

这是视图的代码:

<h1>Listing games</h1>
<%= link_to 'New game', new_game_path, :class => "pure-button pure-button-primary"  %>
<p>
<table class="pure-table sortable">
  <thead>
    <tr>
      <th width="110px">Number</th>
      <th width="300px" >Title</th>
      <th width="110px">Weight</th>
      <th width="110px">Owner</th>
      <th width="120px">Borrowed</th>
      <th width="140px">Borrowed by</th>
      <th class="sorttable_nosort">Action</th>
    </tr>
  </thead>

  <tbody>
  <% @games.each do |game| %>
    <tr>
      <td><%= best_in_place game, :number, :inner_class => "input_number" %></td>
      <td><%= best_in_place game, :title , :inner_class => "input_title" %></td>
      <td><%= best_in_place game, :weight, :inner_class => "input_weight" %></td>
      <td><%= best_in_place game, :owner, :inner_class => "input_owner" %></td>
    <td><%= best_in_place game, :borrowed, as: :checkbox, collection: {false: "No", true: "Yes"} %></td>
    <td><%= best_in_place game, :borrower, :inner_class => "input_borrower" %></td>


    <td><%= link_to 'Show', game_path(game) %> |
      <%= link_to 'Edit', edit_game_path(game) %> |
      <%= link_to 'Destroy', game_path(game),
      method: :delete,
      data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>
  </tbody>
</table>
</p>
</div>

<%= render 'grid_bottom' =%>

非常感谢任何帮助或建议!

0 个答案:

没有答案