Aaron Thomas
Aaron Thomas

Reputation: 509

Rails 3 using devise and best_in_place gem, will not update subscriber model

I have a rails 3 application using devise with the subscribers model. I would like the subscribers to update their account information in place using best_in_place gem, but I can't seem to get it to update the database. It will update on the screen, but not the database.

The error sees to suggest the subscriber existing is a bad thing, but it isn't since it would be impossible to update that subscriber if it didn't exist.

All I want to do is be able to allow the users to update their information in place from a the subscriber/accounts#show page that shows them their details.

my subscriber/accounts controller has this:

    def update
      @subscriber = Subscriber.find(current_subscriber.id)
      @subscriber.update_without_password(params[:subscriber])
    end

I always get these results in the server log:

Processing by Subscribers::AccountsController#update as JSON
Parameters: {"subscriber"=>{"firstname"=>"Aarof"}, "authenticity_token"=>"Sx6kEQy4NC56ovikMs/D9nVPGJt1q5jNCoFnNjFhDu8=", "id"=>"2"}
Subscriber Load (1.9ms)  SELECT `subscribers`.* FROM `subscribers` WHERE `subscribers`.`id` = 2 LIMIT 1
CACHE (0.0ms)  SELECT `subscribers`.* FROM `subscribers` WHERE `subscribers`.`id` = 2 LIMIT 1
(0.2ms)  BEGIN
Subscriber Exists (0.4ms)  SELECT 1 AS one FROM `subscribers` WHERE (`subscribers`.`email` = BINARY '[email protected]' AND `subscribers`.`id` != 2) LIMIT 1
(0.1ms)  ROLLBACK
Redirected to http://localhost:3000/subscribers/accounts/2
Completed 302 Found in 12ms (ActiveRecord: 2.6ms)

my show page looks like this:

%p.subscriber-account-info
  =best_in_place @subscriber, :firstname, :path => subscribers_account_path(@subscriber)

My routes for subscribers looks like:

       subscribers_accounts GET    /subscribers/accounts(.:format)                  subscribers/accounts#index
                            POST   /subscribers/accounts(.:format)                  subscribers/accounts#create
    new_subscribers_account GET    /subscribers/accounts/new(.:format)              subscribers/accounts#new
   edit_subscribers_account GET    /subscribers/accounts/:id/edit(.:format)         subscribers/accounts#edit
        subscribers_account GET    /subscribers/accounts/:id(.:format)              subscribers/accounts#show
                            PUT    /subscribers/accounts/:id(.:format)              subscribers/accounts#update

I just checked trying to update subscribers firstname using the console and received the same message that the subscriber exists and it rolled the transaction back. Is this because of something in Devise?

Upvotes: 2

Views: 561

Answers (1)

hjuskewycz
hjuskewycz

Reputation: 1437

Maybe a little the answer, but do you respond to JSON? here sample code from our project:

def update
    respond_to do |format|
      resource_files_service.update(@resource_file, params[:resource_file], current_user)

      format.html { }
  format.json { respond_with_bip(@resource_file) }
end

Upvotes: 2

Related Questions