Reputation: 1190
I've looked everywhere for a solution to this, but all of the common solutions to this issue aren't working for me. Any help is greatly appreciated.
My problem is just that the rails best_in_place gem doesn't save any of my data after I make a change. It will allow me to type in the new change, but it won't update the database after I press enter (it also doesn't work if I refresh the page, which was the initial problem on the RailsCast for this gem).
Controller code:
def update
respond_to do |format|
if @renter.update_attributes(renter_params)
format.json { render json: @renter }
flash[:success] = "Profile updated"
redirect_to @renter
else
render 'edit'
end
end
end
View page code
<li><span class="content"><b>Name: </b><%= best_in_place @renter, :name %></span></li>
Thanks in advance!
Edit: Adding renter_params from controller
def renter_params
params.require(:renter).permit(:name, :email, :password, :password_confirmation)
end
(Note: I've never had any problems with renter_params per se, my updates always save OK in the database)
Edit: adding code from javascripts/application.js
//= require jquery
//= require best_in_place
//= require best_in_place.purr
//= require jquery_ujs
//= require jquery.purr
//= require bootstrap
//= require turbolinks
//= require_tree .
renters.js.coffee
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
jQuery ->
$('.best_in_place').best_in_place()
Upvotes: 3
Views: 1883
Reputation: 2508
If you haven't yet, modify your gem as this:
gem 'best_in_place', github: 'bernat/best_in_place'
by simply doing gem 'best_in_place'
didn't work for me.
if that doesn't work, as the documentation suggest, replace:
format.json { render json: @renter }
with:
format.json { respond_with_bip(@renter) }
respond_with_bip
is a "utility method you should use in your controller in order to provide the response that is expected by the javascript side, using the :json format", says the documentation. I'm not sure how much this matters as my Rails 4 app is working without it.
Finally, if the update
action is restricted to logged in users only, make sure you are logged in.
Upvotes: 9