views:

42

answers:

2

Hi trying to make a Registration page with Ruby on rails using the tutorial found here

http://rails.francik.name/week4.html

having trouble getting the page to work after adding

<h1>Register</h1>
<enter code here%= error_messages_for :user %>
<% form_for :user do |f| %>
  <p>
    <%= f.label :screen_name %>:
    <%= f.text_field :screen_name %>
  </p>
  <p>
    <%= f.label :e_mail, "E-Mail" %>:
    <%= f.text_field :e_mail %>
  </p>
  <p>
    <%= f.label :password %>:
    <%= f.password_field :password  %>
  </p>
  <p>
    <%= f.submit "Register" %>
  </p>
<% end %>

to the register.rhtml file

when loaded I get

NoMethodError in User#register
Showing app/views/user/register.rhtml where line #5 raised:
undefined method `label' for #<ActionView::Helpers::FormBuilder:0x275ef48>

the application trace is

#{RAILS_ROOT}/app/views/user/register.rhtml:5:in `_run_rhtml_47app47views47user47register46rhtml'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:151:in `fields_for'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/helpers/form_helper.rb:127:in `form_for'
#{RAILS_ROOT}/app/views/user/register.rhtml:3:in `_run_rhtml_47app47views47user47register46rhtml'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `send'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:326:in `compile_and_render_template'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:301:in `render_template'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:260:in `render_file'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:806:in `render_file'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:711:in `render_with_no_layout'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/layout.rb:247:in `render_without_benchmark'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:50:in `render'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:50:in `render'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:1096:in `perform_action_without_filters'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:632:in `call_filter'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:619:in `perform_action_without_benchmark'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/1.8/benchmark.rb:293:in `measure'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/benchmarking.rb:66:in `perform_action_without_rescue'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/rescue.rb:83:in `perform_action'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `send'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:430:in `process_without_filters'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/filters.rb:624:in `process_without_session_management_support'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/session_management.rb:114:in `process'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/base.rb:330:in `process'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:41:in `dispatch'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:78:in `process'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `synchronize'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/rails.rb:76:in `process'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:618:in `process_client'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `each'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:617:in `process_client'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `initialize'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `new'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:736:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `initialize'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `new'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel.rb:720:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:271:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `each'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/configurator.rb:270:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:127:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/lib/mongrel/command.rb:211:in `run'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-1.0.1/bin/mongrel_rails:243
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/bin/mongrel_rails:16:in `load'
/Applications/Locomotive2/Bundles/standardRailsMar2007.locobundle/i386/bin/mongrel_rails:16
+1  A: 

Hey I think this tutorial is out of date! you are referring to .rhtml files (although I did see that register.html.erb was mentioned in the tutorial)

You might want to try something like this:

<h1>Register</h1>
<% form_for @user do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :screen_name %>:
    <%= f.text_field :screen_name %>
  </p>
  <p>
    <%= f.label :e_mail, "E-Mail" %>:
    <%= f.text_field :e_mail %>
  </p>
  <p>
    <%= f.label :password %>:
    <%= f.password_field :password  %>
  </p>
  <p>
    <%= f.submit "Register" %>
  </p>
<% end %>

Edit: Since this didn't work for you, I'm going to start a fresh rails app from scratch to make this work:

prompt>rails test_app
prompt>cd test_app
prompt>script/generate scaffold user screen_name:string e_mail:string password:string
prompt>rake db:migrate
prompt>script/server

point your browser to http://localhost:3000/users/new and it should work. You will get something similar to what I posted above. This can show you that what I gave you SHOULD work but I think something is missing for your app. Try this start to finish and then from there figure out how to get a register action to work.

DJTripleThreat
so should I be using rhtml or html.erb? I am still getting the same error btw. Thanks
msandbot
try my 'tutorial' from start to finish. This should get it to work.
DJTripleThreat
A: 

You Rails version is outdated. You're using rails 1, current is rails 2 and rails 3 is already in beta. Rails 1 doesn't have this function, it was introduces in rails 2

see http://github.com/rails/rails/blob/v1.2.6/actionpack/lib/action_view/helpers/form_helper.rb and http://github.com/rails/rails/blob/v2.0.0/actionpack/lib/action_view/helpers/form_helper.rb

jigfox
Yeah good point. I didn't even notice the version number in the logs.
DJTripleThreat