hashrocket / decent_exposure

A helper for creating declarative interfaces in controllers
MIT License
1.81k stars 107 forks source link

In Update thing.save not working #159

Closed Faisal-nfl closed 8 years ago

Faisal-nfl commented 8 years ago

I used decent_exposure and its working fine for save but not working for update using thing.save but works with thing.update

Where as in another project thing.save works for update I also see an tutorial which thing.save is used for update. Whats the difference???

mattpolito commented 8 years ago

@Faisal-nfl what versions are both projects using?

Faisal-nfl commented 8 years ago

@mattpolito The current project in which thing.save is not working has Version Ruby : 2.3.1 Rails : 5.0.0

The previous project in which it works Ruby : 2.3.1 Rails : 4.2.6

mattpolito commented 8 years ago

@Faisal-nfl I'm sorry, I should have been more clear. What version of decent_exposure are you using in both instances.

Faisal-nfl commented 8 years ago

@mattpolito My bad, should have thought about it In last project it was 2.3.3 and in current project its 3.0.0

hashrocketeer commented 8 years ago

hey @Faisal-nfl, the way a thing is instantiated is slightly different in version 3.0.0, so you'll need to change your code to use thing.update(thing_params). Something like that:

class ThingsController < ApplicationController
  expose :thing

  def update
    if thing.update(thing_params)
      redirect_to thing_path(thing)
    else
      render :edit
    end
  end
end

That's the way we currently do: https://github.com/hashrocket/decent_exposure/blob/master/lib/decent_exposure/behavior.rb#L9