In Place editing

3.8k views Asked by At

I followed all the steps according to http://railscasts.com/episodes/302-in-place-editing?view=asciicast

but it is not editing at the attributes place?

This is my page

<div class="well-lg box-left box-first">
  <div class="row">
    <h3>Personal Details</h3>
    <br>
    <ul class="list-group">
    <li><strong><div class="col-sm-4">FName </div></strong>
      <%= best_in_place @user, :fname %></li>
    <li><strong><div class="col-sm-4">LName </div></strong>
      <%=  best_in_place @user, :lname %></li>
    <li><strong><div class="col-sm-4">Email </div></strong>
      <%=  best_in_place @user, :email %></li>
    <li><strong><div class="col-sm-4">Mobile </div></strong>
      <%=  best_in_place @user, :mob %></li>
    </ul><br><%= link_to 'Edit', {:controller=>'users', :action=>'edit'}%>
  </div>
</div>

Any help or solution?? Thanks in advance

Edit

application.js

//= require jquery
//= require jquery_ujs
//= require jquery.purr
//= require best_in_place
//= require turbolinks
//= require_tree .

user.js.coffee

 jQuery ->
 $('.best_in_place').best_in_place();
3

There are 3 answers

0
Aakash Aggarwal On

Best_in_place is not completely compatible with Rails 4, you can try the following gems and see if they work.

https://github.com/bootstrap-ruby/bootstrap-editable-rails

https://github.com/janv/rest_in_place

0
Nick Ginanto On

It is not enough to put just the helper in the HTML

you need to have the proper code in the controller as well

your controller code should look like this (the json responses)

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

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

as for the helper, not sure if it does this by default, try adding as: :input

see here https://github.com/bernat/best_in_place

0
Abhi On

Although, everything is clear and step by step in documentation, but as per your request, following is the way I'm using it:

application.js

//= require jquery-editable

application.css

*= require jquery-editable

view

<a href="javscript:void(0)" id="some_id">

javascript

jQuery.fn.editable.defaults.mode = 'inline';
jQuery.fn.editable.defaults.ajaxOptions = {type: "PUT"};

jQuery("#some_id").editable({
  type: "text",
  pk: "1",  //This is id of the record which will be updated
  url: url  //The rails URL for controller method
});

Still, I recommend you to go through the documentation for better understanding and smoother implementation.