Toggle! not working


#1

I have a column in the database for called confirmed that is a
tinyint(1).

currently the value is set to 0.

i am trying to use the following function in my controller for
Compounds:

def confirm
@compound = Compound.find(params[:id])
@compound.toggle!(:confirmed)
redirect_to compound_path(@compound)
end

i have my routes like the following:

map.resources :compounds, :collection => { :calculator => :get },
:member => { :confirm => :post }

and this is what the link looks like:

http://domain/compounds/3960/confirm

but for some reason the value of confirmed is not changing. anyone have
any ideas?


#2

Hi Scott,

Try :put instead of :post on the :member param, like this:

map.resources :compounds, :collection => { :calculator
=> :get }, :member => { :confirm => :put }


#3

Elias O. wrote:

Hi Scott,

Try :put instead of :post on the :member param, like this:

map.resources :compounds, :collection => { :calculator
=> :get }, :member => { :confirm => :put }

Elias,

i tried put but got this error back:

Only put requests are allowed.

robert,

i think the toggle should toggle the value from 1->0 or 0->1 but i
can’t even get it to toggle from 0->1 at the moment.


#4

def confirm
@compound = Compound.find(params[:id])
@compound.toggle!(:confirmed)
redirect_to compound_path(@compound)
end

Shouldn’t your confirm method always set the :confirmed flag to true
rather than toggling it anyway? Calling confirm on an already confirmed
item should remain confirmed right? In this case if confirm were called
on a confirmed item it would unconfirm it. It seems that should be a
separate operation to me.