Redirecting with params

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!

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 [email protected]

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 <
[email protected]> wrote:


http://www.rubyplus.org/
Free Ruby and Rails Screencasts

On Wed, Jul 30, 2008 at 2:51 PM, Justin To
[email protected] 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]

Christopher Kintner wrote:

On Wed, Jul 30, 2008 at 2:51 PM, Justin To
[email protected] 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!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs