I finally got a RoR environment working on my PC with instantrails 2.0.
Here is my problem.
I created a database with a "Users" table.
It's structure is the following :
Name, Surnmame, City, age...
The table containing the Users was succesfully scafolded and I have the
adress "localhost:3000/users" running with all the CRUD functions !
now I want to add a link at the botom of the index page allowing me to
filter the users living in Paris (and ultimately, a textbox where I can
put in any search criteria). But getting the filter for the Paris Users
would already end a huge headache.
I added at the bottom of the index page a "Paris" link after the
prebuilt "new user" link.
Hhmm, I'm a noob myself but the way I usually take care of something
like this is to generate a new controller and put my code there. I find
this is the easiest way for me since then I can just restrict access to
the CRUD that scaffold generated for me and use it as part of my Admin
area.
Your problem is with your routes, you have the standard restful routes
setup so it's interpretting the action as an id. I would suggest using
GET variables to do the filter. I would use something like this
I agree with Matt. "filter" and "search" are really indexes with more
specific criteria. If you take the approach he's suggesting you keep
the footprint smaller.
@Brandon: Speaking of not DRY... aren't you logically suggesting that
he create a new controller for every interesting city he can think
of? You're repeating all the lookup code, the routes, etc simply for
the sake of a simple, pretty url. Keeping things DRY is a principle
that crosses the boundaries of classes.
I agree with Matt. "filter" and "search" are really indexes with more
specific criteria. If you take the approach he's suggesting you keep
the footprint smaller.
@Brandon: Speaking of not DRY... aren't you logically suggesting that
he create a new controller for every interesting city he can think
of? You're repeating all the lookup code, the routes, etc simply for
the sake of a simple, pretty url. Keeping things DRY is a principle
that crosses the boundaries of classes.
On May 12, 2:33 pm, Matt Mongeau <rails-mailing-l...@andreas-s.net>
No, not exactly. My background is php and in learning rails I found that
it made more sense to me if I just left the scaffold pages "as is" but
add a berfore filter to restrict access to them. This give me my "admin"
functionally that I normally require. As for the extra controller I
normally make an extra controller that can accept parameters and be
dynamic. I use this controller to display my pages that the end users
see. The example I described is not how I normally do things but was
more of an example of a method he could use to get past the problem he
was having.