New to RoR. Using text input as a parameter in query

I’m new to RoR and I am trying to figure out how to use user input from
a text field as a parameter in a query. I know this is probably simple
but I have been messing around with it for a while and can’t figuire it
out.

The controller has this method:
def search
@events = Event.find(:all, :order => ‘date DESC’,
:conditions => [‘title=?’,titleinput])

respond_to do |format|
  format.html
  format.xml { render :xml => @events }
end

end

and the view:

Title

I know this is probably completely wrong but I couldn’t figure out how
to use the variable from the form in the query in the controller.

Thanks for any help.
Ben

On 4 Apr 2008, at 19:17, Ben Simms wrote:

I know this is probably completely wrong but I couldn’t figure out how
to use the variable from the form in the query in the controller.
In Rails, variables in forms are stored in the params hash so, in your
case, to get the value of titleinput you would do params[:titleinput].
This would change your controller’s search method to the following:

def search
@events = Event.find(:all, :order => ‘date DESC’,
:conditions => [‘title=?’, params[:titleinput]])

respond_to do |format|
  format.html
  format.xml { render :xml => @events }
end

end

Ben Simms wrote:

I’m new to RoR and I am trying to figure out how to use user input from
a text field as a parameter in a query.

In general, Rails questions are better asked on the Rails mailing list.


James B.

“In Ruby, no one cares who your parents were, all they care
about is if you know what you are talking about.”

  • Logan C.

Thanks, that did it. Sorry for the post in the wrong area.

El Viernes, 4 de Abril de 2008, Ben Simms escribió:

I’m new to RoR and I am trying to figure out how to use user input from
a text field as a parameter in a query.

Hi, since RoR is a framework based on Ruby is better you ask this kind
of
questions in a RoR maillist. Note that RoR adds its own “magic” to Ruby
:wink:

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