wbsurfver-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2008-Jul-16 13:46 UTC
_path and _url helpers not working with scaffolding
Here is what is happening, I have rails 2.0.2 on both my local PC running windows XP and my server which is linux. So I generated scaffolding on windows by doing script/generate scaffolding MyRec fld:string fld2:string and so on, then when I moved the code over to linux I kept getting errors for methods of the form: mycontroller_path and mycontroller_url being undefined for the controllers generated for the scaffolds. I looked around on google a bit, and didn''t have any luck. Something about adding something to routes.rb didn''t seem to work with a quick try. I started to define method_missing in my applications_controler and applications_helper, but I''m not sure if there is an easier way to fix this ? I had some success initially doing this, but it seems complex a bit. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thorsten Müller
2008-Jul-16 15:43 UTC
Re: _path and _url helpers not working with scaffolding
method_missing is the wrong approach for sure You must define the resources in routes.rb if the controller is name my_controller, it should look like: map resources :my if that doesn''t help, please post more info. controller name, the generated code that gives the error --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
wbsurfver-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2008-Jul-16 16:34 UTC
Re: _path and _url helpers not working with scaffolding
On Jul 16, 11:43 am, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> method_missing is the wrong approach for sure > You must define the resources in routes.rb > > if the controller is name my_controller, it should look like: > > map resources :my > > if that doesn''t help, please post more info. > controller name, the generated code that gives the errorI did start to go down the named routes path. What mystifies me is that I tried generating scaffolding on linux. If the scaffolding is generated on linux it seems to work fine, but if it''s generated on windows and copied to linux, it doesn''t work quite right, even though it all appears to look the same. What I don''t get at all is the scaffolding creates named routes, but I don''t see where they are created. That''s basically where the problem is. So I went and added some routes by hand in routes.rb for one of my controllers like this: map.criteria ''criterias'', :controller => "criterias", :action => "index" map.criteria ''criteria/edit/:id'', :controller => "criterias", :action => "edit" map.criteria ''criteria/show/:id'', :controller => "criterias", :action => "show" Now I changed my scafolding to look like this for show and edit: <td><%= link_to ''Show'', show_criteria_path(criteria) %></td> <td><%= link_to ''Edit'', edit_criteria_path(criteria) %></td> Show works fine, but when I click on an edit, it appears that my controllers edit method gets called and then it calls render the template. That works fine, I have log messages in the template. The very last line of the template is a log message that shows up in the log ("inside template 4") bellow. The log file indicates a 200 status, but the browser gets a 500 status Parameters: {"action"=>"edit", "id"=>"7", "controller"=>"criterias"} #<Criteria id: 7, title: "test", description: "", salary: "", work_type: "", location: "", zip_code: "", created_at: "2008-07-16 08:26:57", updated_at: "2008-07-16 08:26:57"> Rendering template within layouts/main Rendering criterias/edit inside template#<Criteria id: 7, title: "test", description: "", salary: "", work_type: "", location: "", zip_code: "", created_at: "2008-07-16 08:26:57", updated_at: "2008-07-16 08:26:57"> inside template 1 inside template 2 inside template 3 inside template 4 Completed in 0.06958 (14 reqs/sec) | Rendering: 0.01398 (20%) | DB: 0.00000 (0%) | 200 OK [http://itjobs.freespiritboston.net/criteria/ edit/7] --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
wbsurfver-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2008-Jul-17 14:40 UTC
Re: _path and _url helpers not working with scaffolding
after a bunch of reading and messing around, it seems like if I do my routing like this for each of my scaffolded controllers, then it all seems to work: [''criterias'', ''applicants'', ''companies''].each do |ctl| map.send(ctl, ctl, :controller => ctl, :action => ''create'', :conditions => {:method => ''post''}) map.send(ctl.singularize, ctl.singularize + ''/'' + '':id'', :controller => ctl, :action => ''destroy'', :id => /\d+/, :conditions => {:method => ''post''}) =begin map.recname ''recname/:id'' :controller => "recnames", :action => "show", :id => /\d+/ =end map.send(ctl.singularize, ctl.singularize + ''/'' + '':id'', :controller => ctl, :action => ''show'', :id => /\d+/) =begin map.action_recname ''recname/edit/:id'', :controller => "recnames", :action => action, :id => /\d+/ =end map.send(''edit_'' + ctl.singularize, ctl.singularize + ''/edit/'' + '':id'', :controller => ctl, :action => ''edit'', :id => /\d+/) map.resources ctl end --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
shouldn''t that be script/generate scaffold my_rec fld:string fld2:string On 16 Jul., 15:46, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Here is what is happening, I have rails 2.0.2 on both my local PC > running windows XP and my server which is linux. > > So I generated scaffolding on windows by doing > > script/generate scaffolding MyRec fld:string fld2:string > > and so on, > > then when I moved the code over to linux I kept getting errors for > methods of the form: > mycontroller_path and mycontroller_url being undefined for the > controllers generated for the scaffolds. I looked around on google a > bit, and didn''t have any luck. > Something about adding something to routes.rb didn''t seem to work with > a quick try. > > I started to define method_missing in my applications_controler and > applications_helper, but > I''m not sure if there is an easier way to fix this ? I had some > success initially doing this, but it seems complex a bit.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Conrad Taylor
2008-Aug-31 13:35 UTC
Re: _path and _url helpers not working with scaffolding
Hi, if you want test if your restful routes are working correctly, you can do the following in the root directory of your rails application: 1) add the following to your routes.rb located in the config directory: map.resources :records 2) execute the following: ./script/console 3) Now, type app.records_path Next, the plural of criteria is criterion. Now, how can I correct the inflector to produce the correct pluralization of criteria? You can add the following at the bottom your application''s environment.rb file: Inflector.inflections do |inflect| inflect.irregular ''criteria'', ''criterion'' end 4) Now, when you''re in script/console, you should get the correct pluralization of criteria:>> "criteria".pluralize=> "criterion" Good luck, -Conrad On Sun, Aug 31, 2008 at 5:34 AM, gerold <geroldboehler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > shouldn''t that be > > script/generate scaffold my_rec fld:string fld2:string > > > > On 16 Jul., 15:46, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Here is what is happening, I have rails 2.0.2 on both my local PC > > running windows XP and my server which is linux. > > > > So I generated scaffolding on windows by doing > > > > script/generate scaffolding MyRec fld:string fld2:string > > > > and so on, > > > > then when I moved the code over to linux I kept getting errors for > > methods of the form: > > mycontroller_path and mycontroller_url being undefined for the > > controllers generated for the scaffolds. I looked around on google a > > bit, and didn''t have any luck. > > Something about adding something to routes.rb didn''t seem to work with > > a quick try. > > > > I started to define method_missing in my applications_controler and > > applications_helper, but > > I''m not sure if there is an easier way to fix this ? I had some > > success initially doing this, but it seems complex a bit. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hate to be pedantic, but in fact ''criterion'' is the singular and ''criteria'' is the plural. http://en.wiktionary.org/wiki/criterion i''d bet rails would correctly pluralise criterion to criteria, but not the other way round, because thats wrong. - mungler On Aug 31, 2:35 pm, "Conrad Taylor" <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, if you want test if your restful routes are working correctly, you can > do the following in the root directory of your rails application: > 1) add the following to your routes.rb located in the config directory: > > map.resources :records > > 2) execute the following: > > ./script/console > > 3) Now, type > > app.records_path > > Next, the plural of criteria is criterion. Now, how can I correct the > inflector to produce the correct pluralization of criteria? You can add the > following at the bottom your application''s environment.rb file: > > Inflector.inflections do |inflect| > inflect.irregular ''criteria'', ''criterion'' > end > > 4) Now, when you''re in script/console, you should get the correct > pluralization of criteria: > > >> "criteria".pluralize > > => "criterion" > > Good luck, > > -Conrad > > On Sun, Aug 31, 2008 at 5:34 AM, gerold <geroldboeh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > shouldn''t that be > > > script/generate scaffold my_rec fld:string fld2:string > > > On 16 Jul., 15:46, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Here is what is happening, I have rails 2.0.2 on both my local PC > > > running windows XP and my server which is linux. > > > > So I generated scaffolding on windows by doing > > > > script/generate scaffolding MyRec fld:string fld2:string > > > > and so on, > > > > then when I moved the code over to linux I kept getting errors for > > > methods of the form: > > > mycontroller_path and mycontroller_url being undefined for the > > > controllers generated for the scaffolds. I looked around on google a > > > bit, and didn''t have any luck. > > > Something about adding something to routes.rb didn''t seem to work with > > > a quick try. > > > > I started to define method_missing in my applications_controler and > > > applications_helper, but > > > I''m not sure if there is an easier way to fix this ? I had some > > > success initially doing this, but it seems complex a bit.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in fact, criterion is the singular and criteria is the plural: http://en.wiktionary.org/wiki/criterion i''d bet rails would *correctly* pluralize criterion to criteria, but not the other way round... - mungler On Aug 31, 2:35 pm, "Conrad Taylor" <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, if you want test if your restful routes are working correctly, you can > do the following in the root directory of your rails application: > 1) add the following to your routes.rb located in the config directory: > > map.resources :records > > 2) execute the following: > > ./script/console > > 3) Now, type > > app.records_path > > Next, the plural of criteria is criterion. Now, how can I correct the > inflector to produce the correct pluralization of criteria? You can add the > following at the bottom your application''s environment.rb file: > > Inflector.inflections do |inflect| > inflect.irregular ''criteria'', ''criterion'' > end > > 4) Now, when you''re in script/console, you should get the correct > pluralization of criteria: > > >> "criteria".pluralize > > => "criterion" > > Good luck, > > -Conrad > > On Sun, Aug 31, 2008 at 5:34 AM, gerold <geroldboeh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > shouldn''t that be > > > script/generate scaffold my_rec fld:string fld2:string > > > On 16 Jul., 15:46, "wbsurf...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org" <wbsurf...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Here is what is happening, I have rails 2.0.2 on both my local PC > > > running windows XP and my server which is linux. > > > > So I generated scaffolding on windows by doing > > > > script/generate scaffolding MyRec fld:string fld2:string > > > > and so on, > > > > then when I moved the code over to linux I kept getting errors for > > > methods of the form: > > > mycontroller_path and mycontroller_url being undefined for the > > > controllers generated for the scaffolds. I looked around on google a > > > bit, and didn''t have any luck. > > > Something about adding something to routes.rb didn''t seem to work with > > > a quick try. > > > > I started to define method_missing in my applications_controler and > > > applications_helper, but > > > I''m not sure if there is an easier way to fix this ? I had some > > > success initially doing this, but it seems complex a bit.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---