jeudi 23 juillet 2015

Best in place gem not updating values - rails 4

so i have installed best in place gem in a rails 4 environment and initialised it correctly. (i can click on the name field and the box becomes editable).

I've this code in my admin_namespaced user controller

class Admin::UsersController < Admin::BaseController
  def index
    @users = User.all
    # @columns = User.column_names
  end

  def show
    @user = User.find(params[:id])
  end

  def update
    @user = User.find params[:id]

    respond_to do |format|
      if @user.update_attributes(user_params)
        format.html { redirect_to(user, :notice => 'User was successfully updated.') }
        format.json { respond_with_bip(@user) }
      else
        format.html { render :action => "index" }
        format.json { respond_with_bip(@user) }
      end
    end
  end

  private

    def user_params
      params.require(:user).permit(:name,:email,:password,:password_confirmation)
    end
end

and basically i want to use it in conjuction with rails datatables gem that i successfully setup, to inline-edit corresponding fields.

this is the html.erb code in my user index view

<% provide(:title, 'All users') %>
<h1>All users</h1>

<%= link_to "Back", admin_path %>
<table class="display responsive no-wrap text-center" id="usertableadmin">
  <thead>
    <tr>
      <th>id</th>
      <th>Username</th>
      <th>Email</th>
      <th>Activated?</th>
      <th>Admin?</th>
    </tr>
  </thead>
  <tbody>
    <% @users.each do |user| %>
      <tr>
        <td><%= user.id %></td>
        <td><%= best_in_place user, :name%></td>
        <td><%= user.email %></td>
        <td><%= user.activated %></td>
        <td><%= user.admin %></td>
      </tr>
    <% end %>
  </tbody>

</table>

here is what the html code looks like on the tag that has the best_in_place initialization.

<span data-bip-type="input" data-bip-attribute="name" data-bip-object="user"     data-bip-original-content="Example User" data-bip-url="/users/1" data-bip-value="Example User" class="best_in_place" id="best_in_place_user_1_name">Example User</span>

I dont know for sure but for some reason the fields do not get updated. When i click to change the name it gets reverted to the previous one.

I dont know if its because i have a namespace, admin/users or its because its the index action and not the show action.

any insight is welcome.

Aucun commentaire:

Enregistrer un commentaire