Hi all. I have a web app where by people submit data to the DB. I have a
page that lists the last 5 submissions by the ID number. This allows a
user to click one of the last 5 and it brings up all the data for that
ID. e.g. /posts/121314 Id being 121314 for example. This all works
fine. However I have a search page which is just a box which asks the
user to either search the ID if known or company name by entering it in
a form_for helper box. This bit I am having soo much trouble with.
For example, ideally if a user enters the id number in the box, lets say
it's 12345 it routes directly to /posts/12345 as this will show the
data.
Also I need that when they enter the company name it searches the db and
then lists all entry id's that also have this name assigned to them.
Once that bit is done I can continue with making them link to the pages
etc...
so i Have a search page within my posts controller as below and when
they enter on the form more so for the company name it send it to the
'searchshow' page to lists the entries. Both these are currently empty.
def search
end
def search show
end
any help or pointers in the write direction will be great. I have seen
lots of info regarding search etc but they don't really cover my needs.
I am new to ruby and rails really as you can tell.
I would start by TDDing a class/method that will take your various
expected inputs and tell them apart. Then use the output of that to
generate the appropriate 'where' statement to select what you want
from the DB (assuming you don't need anything too sophisticated,
e.g. fuzzy search, stemming, etc.).
After that, easy-peasy, it's just redirects and views.