# Redirect to new action not working?

**URL:** <https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335>\
**Category:** Rails\
**Created:** [February 6, 2008, 9:33pm UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335 "2008-02-06T21:33:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 6, 2008, 9:33pm UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/1 "2008-02-06T21:33:39Z")

</div>

any idea what’s wrong here: agreement return either 0 or 1

def select  
@imitem = Imitem.find(params[:id])

if [params[:agreement] == ‘True’]  
redirect\_to :action =\> ‘agreement’, :id =\> @imitem and return false  
else  
redirect\_to :action =\> ‘options’, :id =\> @imitem and return  
end  
end

it always goes to agreement action no matter what …

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 6, 2008, 9:46pm UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/2 "2008-02-06T21:46:39Z")

</div>

On 2/6/08, KTU [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> any idea what’s wrong here: agreement return either 0 or 1
> 
> def select  
> @imitem = Imitem.find(params[:id])
> 
> if [params[:agreement] == ‘True’]

This isn’t bash 🙂 [params[:agreement] == ‘True’] is an array  
containing one element, this isn’t nil or false and so is always  
handled as true by the if. Remove the outer square brackets and you  
should be ok.

Fred

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 6, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/3 "2008-02-06T22:24:07Z")

</div>

Well I removed those ie. its now (agreement value on database is  
either 1 or 0)

if params[:agreement] == ‘True’  
redirect\_to :action =\> ‘agreement’, :id =\> @imitem and return  
else  
redirect\_to :action =\> ‘options’, :id =\> @imitem and return  
end  
end

but now it goes to options action all the time

On Feb 6, 10:45 pm, “Frederick C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 6, 2008, 11:16pm UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/4 "2008-02-06T23:16:45Z")

</div>

Is params[:agreement] supposed to be a boolean? If not what other  
possible values are there?  
Could you mean ‘true’?

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 6, 2008, 11:26pm UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/5 "2008-02-06T23:26:10Z")

</div>

Hi

agreement on database has value either 0 (zero) or 1 (one). Now I try  
to check if that value is 1 (true) and then it should  
take route (action) to agreement and if not then route (action) should  
go to options.

I tested with all possible values like: True / true / 1 … but all  
those fails…

is that whole statement then wrong somehow… I am still waiting good  
book and its hard to find proper examples from the net.

On Feb 7, 12:16 am, “removed\_email\_address@domain.invalid” \<ESPN3.DL-

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 7, 2008, 10:45am UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/6 "2008-02-07T10:45:14Z")

</div>

ok i found how to do it:

if @imitem.agreement == true

---

<div class="post-metadata">

**Author:** ![KTU](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/ecae2f/32.png) [@KTU](https://www.ruby-forum.com/u/KTU)\
**Post date:** [February 8, 2008, 12:01am UTC](https://www.ruby-forum.com/t/redirect-to-new-action-not-working/128335/7 "2008-02-08T00:01:52Z")

</div>

For a good book I would check out ‘The Rails Way’ published by Addison  
Wesley.

I have some examples on my blog: [http://matthewcarriere.com](http://matthewcarriere.com)

And feel free to email me with a posting topic you would like to see.
