Jump to content

The ultimate community for Ruby on Rails developers.


Photo

noob search form


  • Please log in to reply
1 reply to this topic

#1 macinrack

macinrack

    Passenger

  • Members
  • 1 posts

Posted 24 February 2014 - 05:35 PM

I am new and lost, and on week 3. I have read all the links, done tutorials, but understand little of it. I created two models using scaffold. I have populated my tables with some data. I need to create a search page which will perform a query. I am hoping my association is correct- I'll find out later, but first I need to have a general overview of the steps I need to take to create a search page to make my simple query work. I can probably google well enough if I can figure out which questions to ask.

 

I created a file: views/search.html.erb with code that will generate a form field and a submit button. My first issue is being able navigate to it in my browser. Then I need to figure out how to make it functional, so when I hit submit, my query looks at both models and does the join, blah blah.

 

The scaffold thing worked well for me because I am a bit better at reverse engineering than I am at forward. Seeing the files scaffold created made helped greatly. i would have been forever trying to figure all that out. What I need is some sort of example like that- how to create a search page to make queries.

 

 

 

Thanks



#2 danielhanke

danielhanke

    Signalman

  • Members
  • 12 posts
  • LocationCologne, Germany

Posted 02 March 2014 - 05:54 PM

hey macinrack,

 

a search form and its results can be done in so many ways.

 

One of wich is to create a non-active-record model (http://railscasts.co...19-active-model) to handle and validate the search request.

nothing to be stored/persisted in a database here / yet.

 

then, when information are collected, you can perform the search requets on all the models you want to include in your search.

Book-model when you search for book-titles, User-model when you search for users, and so on.

 

in the end you got a result-set of whatever you searched for. this result set can be rendered like scaffolding does. in both cases you have a set of results..

 

i prevented to show example code here, in order to not take away the chance of learning it on your own. however, ask back if you need additional information. Best Regards and good luck! :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users