Hi! In order to respect DRY principles, I had to regroup two controller in one. To sum up, I have to build one controller which can make a ''simple'' page and this same page with other features when a second id param is entered in the url. This is why, I modified the file ''routes.rb'' so the action could access to 2 params: :id and :tuto_id In the controller, only :id is mandatory I would like to control if the url contains the param :tuto_id I wrote the controller: unless params[:tuto_id].nil? if Tuto.exists? params[:tuto_id] @tuto = Tuto.find(params[:tuto_id])....... And in the view when I want to show more objects when the url contains params[:tuto_]id <% unless @tuto.nil? %>...... When the url contains just the params :id, there is no problems but when it contains the two params, I have the error: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id Is my strategy the right one ? Does this error refers to a another problem ? Thanxs -- 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 11/5/07, Achille Pinson <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi! > > In order to respect DRY principles, I had to regroup two controller in > one. To sum up, I have to build one controller which can make a ''simple'' > page and this same page with other features when a second id param is > entered in the url. > > This is why, I modified the file ''routes.rb'' so the action could access > to 2 params: :id and :tuto_id > > In the controller, only :id is mandatory > I would like to control if the url contains the param :tuto_id > > I wrote the controller: > unless params[:tuto_id].nil? > if Tuto.exists? params[:tuto_id] > @tuto = Tuto.find(params[:tuto_id]).......This could be simplified: @tuto = Tuto.find(params[:tuto_id]) if params[:tuto_id] (This will raise an exception if an invalid tuto_id is passed)> > And in the view when I want to show more objects when the url contains > params[:tuto_]id > <% unless @tuto.nil? %>......The nil? test is unecessary. You can just use <% if @tuto %>. But what you have should work fine.> > When the url contains just the params :id, there is no problems but when > it contains the two params, I have the error: > Called id for nil, which would mistakenly be 4 -- if you really wanted > the id of nil, use object_id > > > Is my strategy the right one ? > Does this error refers to a another problem ?The error is coming from somewhere else. Look at the backtrace information in the error report. It looks like you''re probably using @tuto.id somewhere, but @tuto is nil. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanxs, I found the error, you were right: it was somewhere else Thanxs for the simplifications too ! -- 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 -~----------~----~----~----~------~----~------~--~---