Hello everyone, I have a little problem, since I have change my route from resources to resource. My files look like: # config/routes.rb ActionController::Routing::Routes.draw do |map| map.resource :system end # app/controllers/systems_controller.rb class SystemsController < ApplicationController def new @system = System.new end end # app/views/systems/new.html.erb <% form_for @system do |f| %> <%= f.error_messages %> And here is my error message: NoMethodError in Systems#new Showing app/views/systems/new.html.erb where line #1 raised: undefined method `systems_path'' for #<ActionView::Base:0x3459fe0> Extracted source (around line #1): 1: <% form_for @system do |f| %> 2: <%= f.error_messages %> 3: 4: <dl> RAILS_ROOT: /Users/pulu/Sites/test Do you think I get an error in new.html.erb? 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 -~----------~----~----~----~------~----~------~--~---
try... <% form_tag system_path do %> using @system is a shortcut way of writing systems_path but it looks for the plural path - you''ve set yours to a singular resource path run "rake routes" to see your available paths in the terminal window. Hope that helps On Apr 20, 8:07 am, "Paul A." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello everyone, > > I have a little problem, since I have change my route from resources to > resource. My files look like: > > # config/routes.rb > ActionController::Routing::Routes.draw do |map| > map.resource :system > end > > # app/controllers/systems_controller.rb > class SystemsController < ApplicationController > def new > @system = System.new > end > end > > # app/views/systems/new.html.erb > <% form_for @system do |f| %> > <%= f.error_messages %> > > And here is my error message: > > NoMethodError in Systems#new > > Showing app/views/systems/new.html.erb where line #1 raised: > > undefined method `systems_path'' for #<ActionView::Base:0x3459fe0> > Extracted source (around line #1): > > 1: <% form_for @system do |f| %> > 2: <%= f.error_messages %> > 3: > 4: <dl> > RAILS_ROOT: /Users/pulu/Sites/test > > Do you think I get an error in new.html.erb? > > Thanks > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gavin Morrice wrote:> try... > <% form_tag system_path do %>Thanks, Gavin. When I do this, I get an error at the line 2 about: <%= f.error_messages %> To solve it, I had just rewrite this line with: <%= error_messages %> But an other error message is occuring, saying that "error_messages" is not defined (if I remember well). -- 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 -~----------~----~----~----~------~----~------~--~---
Sorry - should have explained: If you use the form_tag method then you can''t pass a variable like |f| you''d have to replace things like f.text_field :your_field with text_field :system, :your_field and use the error_messages_for method instead: http://api.rubyonrails.org/classes/ActionView/Helpers/ActiveRecordHelper.html#M001662 I think you can use form_for as you did before but write it like: <% form_for :system, :url => {:action => :create} do |f| %> This would be the easiest option but I''m not 100% sure if that works with a singular resource. Would be curious to find out if it does? On Apr 20, 10:14 am, "Paul A." <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Gavin Morrice wrote: > > try... > > <% form_tag system_path do %> > > Thanks, Gavin. When I do this, I get an error at the line 2 about: > <%= f.error_messages %> > > To solve it, I had just rewrite this line with: > <%= error_messages %> > > But an other error message is occuring, saying that "error_messages" is > not defined (if I remember well). > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Many thanks, Gavin Morrice. Thanks to your answer, I had making some modifications to gets this: <% form_tag system_path do %> <%= error_messages_for ''system'' %> ... <%= submit_tag ''Create'' %> <% end %> After testing this line: <% form_for :system, :url => {:action => :create} do |f| %> it''s okay too. -- Posted via http://www.ruby-forum.com/.