Get a value from previous page

how could i get a value from previus page? for example

on EVENT show view i have

<%= link_to 'New Message', new_message_path( :event_id => @event.id) %>

and i need to get the event id on the new_message page to send it when creating the message

As far as I understand your question you need to use the params hash- like object.

i need something like this

index.html.erb

<th><%= link_to 'cost', :action => 'search', [b]:order[/b] => 'cost' %></th>

cars_controller.rb

  def search     @order = [b]:order[/b]   @cars = Car.paginate :page => params[:page], :order => @order     respond_to do |format|       format.html # index.html.erb       format.xml { render :xml => @cars }     end   end

i need something like this

index.html.erb

<th><%= link_to 'cost', :action => 'search', [b]:order[/b] => 'cost' %></th>

cars_controller.rb

def search @order = [b]:order[/b]

I don't understand what you are trying to do with the [b] [/b]

Colin

what [b] [/b] :S

Please quote the previous message so your response can be understood. Thanks.

what [b] [/b] :S

In your previous message you have

<th><%= link_to 'cost', :action => 'search', [b]:order[/b] => 'cost'

and

   @order = [b]:order[/b]

I don't understand what the [b] and [/b] are for. It is not valid ruby. I also don't understand what question you are asking for help with.

Colin

i need something like this

index.html.erb

<th><%= link_to 'cost', :action => 'search', :order => 'cost' %></th>

cars_controller.rb

  def search     @order = :order   @cars = Car.paginate :page => params[:page], :order => @order     respond_to do |format|       format.html # index.html.erb       format.xml { render :xml => @cars }     end   end

give a value from the view to the controller that way give value: :order => 'cost' receive value: @order = :order but i dont know if it can be done like that

take a look at what gets passed to your controller (in particular any url query parameters are stored in params[:parameter_name]

Fred

Look in the log file (development.log assuming you are in development mode) and you will see the parameters passed to the controller when you click the link. The parameters passed are then available in the params hash. So your :order variable should be available as params[:order].

I suggest you run through some tutorials to get an understanding of basic Rails operation. The one at railstutorial.org (available free online) is good.

Also have a look at the Rails Guides.

Colin

I dont need @order ar params I need it as a value

Please quote the previous message and insert your comments at the appropriate point, this makes it easier to follow the thread.

I dont need @order ar params I need it as a value

I have no idea what you mean by that. params[:order] *is* a value. You can say @order = params[:order]

If I misunderstand your problem please try to explain again.

Colin

Colin Law wrote in post #972821:

You do not need me to answer that, your automated tests will tell you whether it does or not. However that is a horrible way to do it. Firstly a small point, the variable @order can just be order, unless you want the variable to be accessible in the view. Secondly, however, imagine what would happen if someone sends an http request with an SQL snippet in :order. That will get inserted into the SQL of the find and could wreck your database. A better way would be to test the value of params[:order] for a set of valid values and use the appropriate order setting in the call to paginate.

Colin