# Redirect\_to difficulties

**URL:** <https://www.ruby-forum.com/t/redirect-to-difficulties/107745>\
**Category:** Rails\
**Created:** [June 25, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/redirect-to-difficulties/107745 "2007-06-25T22:15:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 25, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/redirect-to-difficulties/107745/1 "2007-06-25T22:15:05Z")

</div>

I’ve been working on a create function that takes some information from  
the user, compares it against existing records and, based on the results  
of that comparison, decides how to act.

There is also the chance that if none of the user records match, the  
system does nothing. The user’s new input is not saved, and the user is  
just returned to the list page.

Everything works perfectly - including the if and elsif portions.

What is not working is that last: redirect\_to :action =\> ‘list’

If the function cycles through all of the Master records and still has  
not found a match, it should redirect back to the list without saving.  
Unfortunately, it keeps sending the user to create.rhtml page instead.

Any ideas? 😕

def create  
@contact = Contact.new(params[:contact])

```
Master.find(:all, :conditions => { :firstname =>

```

@contact.firstname,  
:lastname =\> @contact.lastname  
}).each do |master|

```
    if (Some Criteria)
           Various actions are in here but omitted.
           @contact.save
           redirect_to (:action => 'list', :id => @contact) and

```

return

```
    # If not, does the entry match the Level 2 criteria?
    elsif (Some Criteria)
           Various actions are here, too.
           @contact.save
           redirect_to (:action => 'list', :id => @contact) and

```

return

```
    end

redirect_to :action => 'list'

end

```

end

---

<div class="post-metadata">

**Author:** ![revanche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ac91a4/32.png) [@revanche](https://www.ruby-forum.com/u/revanche)\
**Post date:** [June 25, 2007, 10:17pm UTC](https://www.ruby-forum.com/t/redirect-to-difficulties/107745/2 "2007-06-25T22:17:45Z")

</div>

Nevermind. I had the redirect\_to up on END more than it should have been  
☹
