Hi, I''m new to Rails but I develop in PHP somtimes. I figured that the best way to learn Rails is to create a simple CMS. While I understand the basics of ruby and rails, one issue has caught me: how can I set a default ID for an action? Here is my code for the index action in my pages controller: def index @page = Page.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @page } end end However, when I load http://localhost:3000/pages , I get a message: Couldn''t find Page without an ID How can I make my application assume a default ID of 1 if none is provided? --~--~---------~--~----~------------~-------~--~----~ 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 Mar 6, 2008, at 12:12 PM, Tom Savage wrote:> Hi, I''m new to Rails but I develop in PHP somtimes. I figured that the > best way to learn Rails is to create a simple CMS. While I understand > the basics of ruby and rails, one issue has caught me: how can I set a > default ID for an action? > > Here is my code for the index action in my pages controller: > > def index > > @page = Page.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @page } > end > end > > However, when I load http://localhost:3000/pages , I get a message: > > Couldn''t find Page without an ID > > How can I make my application assume a default ID of 1 if none is > provided?I''m not sure that''s what you want to do. In Rails 2.0.x, the mapping is: GET => action => index => list of items GET /id => action => show => individual item identified by id Run rake routes to see how your HTTP verbs map to your controller/ action pairs. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe I should look at some other examples --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Tom Savage wrote:> Maybe I should look at some other examplesdef pages if params[:id] @hotel = Hotel.find(params[:id]) else @hotel = Hotel.find(:all) end end HOpe it can help you. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Reinhart Ariando WEB: Teapoci.Blogspot.com YM : Booking2Heaven MSN: reinhart.showbiz-EMRzualFZlQ@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 -~----------~----~----~----~------~----~------~--~---
Yeah, that''s good, thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---