# Redirecting with params

**URL:** <https://www.ruby-forum.com/t/redirecting-with-params/144557>\
**Category:** Rails\
**Created:** [July 30, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/redirecting-with-params/144557 "2008-07-30T21:51:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 30, 2008, 9:51pm UTC](https://www.ruby-forum.com/t/redirecting-with-params/144557/1 "2008-07-30T21:51:21Z")

</div>

def index  
@posts = Post.search(params[:search], params[:page])  
session.model.update\_attribute(:viewing, “Home”)  
end

def save\_requirement  
@post = Post.new(params[:post])

```
    if @post.save
      params[:search] = @post.title
      redirect_to :action => :index
    end

```

end

the params[:search] from save\_requirement doesn’t make it through the  
redirect, why is this? What can I do to make it work?

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 30, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/redirecting-with-params/144557/2 "2008-07-30T22:41:08Z")

</div>

this will fix it.

```
     if @post.save
       params[:search] = @post.title
       redirect_to :action => :index, :search => params[:search]
    end

```

On Jul 30, 3:51 pm, Justin To [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 30, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/redirecting-with-params/144557/3 "2008-07-30T22:41:08Z")

</div>

Use flash[:notice] = @post.title then in the view you can render the  
string  
contained in the flash.

On Wed, Jul 30, 2008 at 12:51 PM, Justin To \<  
removed\_email\_address@domain.invalid\> wrote:

> 

–  
[http://www.rubyplus.org/](http://www.rubyplus.org/)  
Free Ruby and Rails Screencasts

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 9:54am UTC](https://www.ruby-forum.com/t/redirecting-with-params/144557/4 "2008-07-31T09:54:51Z")

</div>

On Wed, Jul 30, 2008 at 2:51 PM, Justin To  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> params[:search] = @post.title
> redirect_to :action => :index
> end
> 
> ```
> 
> end
> 
> the params[:search] from save\_requirement doesn’t make it through the  
> redirect, why is this? What can I do to make it work?

You need to include what ever parameters you want after the redirect  
in the redirect.

redirect\_to :action =\> :index, :search =\> params[:search]

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/redirecting-with-params/144557/5 "2008-07-31T18:03:30Z")

</div>

Christopher Kintner wrote:

> On Wed, Jul 30, 2008 at 2:51 PM, Justin To  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ```
> > params[:search] = @post.title
> > redirect_to :action => :index
> > end
> > 
> > ```
> > 
> > end
> > 
> > the params[:search] from save\_requirement doesn’t make it through the  
> > redirect, why is this? What can I do to make it work?
> 
> You need to include what ever parameters you want after the redirect  
> in the redirect.
> 
> redirect\_to :action =\> :index, :search =\> params[:search]

Great, thanks guys!
