# Toggle! not working

**URL:** <https://www.ruby-forum.com/t/toggle-not-working/152982>\
**Category:** Rails\
**Created:** [November 10, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/toggle-not-working/152982 "2008-11-10T21:11:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [November 10, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/toggle-not-working/152982/1 "2008-11-10T21:11:02Z")

</div>

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](http://domain/compounds/3960/confirm)

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

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [November 10, 2008, 10:06pm UTC](https://www.ruby-forum.com/t/toggle-not-working/152982/2 "2008-11-10T22:06:22Z")

</div>

Hi Scott,

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

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

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [November 10, 2008, 10:38pm UTC](https://www.ruby-forum.com/t/toggle-not-working/152982/3 "2008-11-10T22:38:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![skirkpatrick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/73ab20/32.png) [@skirkpatrick](https://www.ruby-forum.com/u/skirkpatrick)\
**Post date:** [November 10, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/toggle-not-working/152982/4 "2008-11-10T22:24:37Z")

</div>

> 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.
