Hi all, I''m new to RoR 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 ! :D 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. the bottom of my index page looks like this : ****************************************************************** <%= link_to ''New user'', new_user_path %> <%= link_to ''paris'',{:controller => "users", :action => "paris" }%> ******************************************************************** I added the "Paris" control in "users_controller.rb" wich I left empty but I get the same error no matter what I put in it... **************************************** def paris end **************************************** Everytime I click on the link I get the following error : ******************************************************** "ActiveRecord::RecordNotFound in UsersController#show Couldn''t find User with ID=paris" ******************************************************** I am unable to add new controls as I always get "Couldn''t find User with ID=paris" no matter what I put in the Paris action. There i probably some RoR concept I didn''t get right... thanx for your help ! levkowalski-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try it like this. <%= link_to "Paris", :controller => :users, :action => :paris %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brandon Roberts wrote:> Try it like this. > > <%= link_to "Paris", :controller => :users, :action => :paris %>I get the same exact error :/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Leo Kowalsky wrote:> Brandon Roberts wrote: >> Try it like this. >> >> <%= link_to "Paris", :controller => :users, :action => :paris %> > > I get the same exact error :/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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I can verify that this does work although it probably isn''t DRY enough for most rails developers. Open terminal in project directory and run: script/generate controller paris add the following to the controller: def index #put your database code here end and now your link becomes: <%= link_to :controller => :paris %> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Brandon Roberts wrote:> I can verify that this does work although it probably isn''t DRY enough > for most rails developers. > > Open terminal in project directory and run: > script/generate controller paris > > add the following to the controller: > def index > #put your database code here > end > > and now your link becomes: > > <%= link_to :controller => :paris %>I put <%= link_to ''paris'', controller => :paris %> in my index.html.rb and "paris_controller.rb" contains : ************************************************** class ParisController < ApplicationController def index #put your database code here end end *************************************************** I still get the same error O_< "Couldn''t find User with ID=paris" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <%= link_to "Users", :action => "index", :filter => "Paris" %> now in your index action you do something like if(params[:filter]) @users = User.find(:all, :conditions => "users.city = ''#{params[:filter]}''") else @users = User.find(:all) end Hope this works for you -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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 > > <%= link_to "Users", :action => "index", :filter => "Paris" %> > > now in your index action you do something like > > if(params[:filter]) > @users = User.find(:all, :conditions => "users.city > ''#{params[:filter]}''") > else > @users = User.find(:all) > end > > Hope this works for you > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On May 12, 2008, at 2:58 PM, AndyV wrote:> 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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: >> 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 >> >> <%= link_to "Users", :action => "index", :filter => "Paris" %> >> >> now in your index action you do something like >> >> if(params[:filter]) >> @users = User.find(:all, :conditions => "users.city >> ''#{params[:filter]}''") >> else >> @users = User.find(:all) >> end >> >> Hope this works for youYou''d be better off specifying the conditions as: :conditions => { :city => params[:filter] } or :conditions => [''city = ?'', params[:filter] ] to avoid SQL Injection attacks. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thank you so much Matt Mongeau... This forum is really helpfull to beginners as there isn''t that much good RoR documentation on the net (or perhaps I''m not going on the right sites...) Does anybody know about a good lightweight editor where I can open and edit my RailsApps from my instantrails directory? Because I''m working with notepad++ :/ thanks ! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
AndyV wrote:> 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...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Anyways everything works now so thank you all -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/12/08, Leo Kowalsky <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> This forum is really helpfull to beginners as there isn''t that much good > RoR documentation on the net (or perhaps I''m not going on the right > sites...)I find this very helpful: http://start.gotapi.com/ I set the check boxes depending on what I''m working on that day or week or whatever. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for all your help. I am wondering now how I can put a searchbox at the botom of the index page to search through the users (by age, city ect...) I tried to inspire myself with the content in "new.html.erb" for the textbox and submit button but I''m not getting anywhere... thanks in advance! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I put <%= text_field_tag :query %> at the bottom of my page but how do I add a button to handle the content of the searchbox so that I can use it as filter? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Leo Kowalsky wrote:> I put > > <%= text_field_tag :query %> > > at the bottom of my page but how do I add a button to handle the content > of the searchbox so that I can use it as filter?Here is the code for one of my search forms <% form_tag posts_path, :method => ''get'' do %> <% content_tag :label do %> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search" %> <% end %> <% end %> Here is the relevant section from tho controller: def index @posts = Post.search params[:search], params[:page] if params[:category_id] != nil @posts = Post.category params[:category_id], params[:page] end respond_to do |format| format.html # index.html.erb format.xml { render :xml => @posts } end end Just a side note but I am also using mill_paginate in this program. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---