Can someone please help a very eager Rails newbie?

ok, so I am trying to learn the ‘c’ in crud from a tutorial right
now. Using the source below, I am loading the action ‘new’, filling
out a form to create a new record, and submitting the form to save the
record. The problem comes when I submit the form. The app generates
an error saying that the method commit= is not defined. At this
point, I don’t know enough about rails to extrapolate meaning from
this weirdness or to know what I should include in this request that’d
help someone to help me.

================================
SOURCE:

CONTROLLER:

class PublicController < ApplicationController

def album_list
@page_title = ‘railstest/public/album_list (Original)’
@albums = Album.find_by_sql(‘SELECT * FROM albums;’)
end

def alt_album_list
@page_title = ‘railstest/public/alt_album_list’
release_date = ‘2003-01-01’
@albums = Album.find(:all,
:order => ‘title, release_date ASC’)
render(:action => ‘album_list’)
end

def show_album
@page_title = ‘railstest/public/show_album (Inspect Album)’
@album = Album.find(:first)

end

def show
@album = Album.find(params[:id])
render(:action => :show_album)
end

def create
@album = Album.new(params)
if @album.save

redirect_to(:action => ‘show’, :id => @album.id)

  redirect_to(:action => 'alt_album_list')
else
  render(:action => 'new')
end

end

def new
@album = Album.new
@page_title = ‘New Model’

end

end

CREATION FORM PAGE:

Rails DB: <%= @page_title %>

<% form_tag(:action => ‘create’) do -%>
Id: <%= text_field(:id, @album.id) %>

Artist: <%= text_field(:artist, @album.artist) %>

Title: <%= text_field(:title, @album.title) %>

Genre: <%= text_field(:genre, @album.genre) %>

Release Date: <%= datetime_select(:release_date,
@album.release_date, :start_year => 1960, :end_year => 2008) %>

<%= submit_tag(‘Create’) %>

<% end -%>




<%= debug(params) %>

VIEW ON SUCCESS:

Rails DB: <%= @page_title %>

<% for album in @albums -%>
<%= link_to(album.artist, :controller => ‘public’, :action =>
‘show’, :id => album.id) %> - <%= album.title %> (<%= album.id %>)<br /

<% end -%>

ON FAIL IT SHOULD GO BACK TO CREATION FORM PAGE

================================
ERROR:

NoMethodError in PublicController#create

undefined method `commit=’ for #Album:0x6068320

RAILS_ROOT: C:/www/railstest
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
attribute_methods.rb:251:in method_missing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2361:insend’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2360:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2130:ininitialize’
app/controllers/public_controller.rb:28:in new' app/controllers/public_controller.rb:28:increate’

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
attribute_methods.rb:251:in method_missing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2361:insend’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2360:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2130:ininitialize’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:1162:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:1162:inperform_action_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
filters.rb:580:in call_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:573:inperform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ rescue.rb:201:inperform_action_without_caching’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
caching/sql_cache.rb:13:in perform_action' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ connection_adapters/abstract/query_cache.rb:33:incache’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
query_cache.rb:8:in cache' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ caching/sql_cache.rb:12:inperform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:529:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:529:inprocess_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
filters.rb:569:in process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ session_management.rb:130:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:389:in process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:149:inhandle_request’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:107:in dispatch' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:104:insynchronize’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:104:in dispatch' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:120:indispatch_cgi’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:35:in dispatch' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/ rails.rb:76:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
rails.rb:74:in synchronize' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/ rails.rb:74:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
159:in process_client' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 158:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
158:in process_client' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 285:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
285:in initialize' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 285:innew’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
285:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 268:ininitialize’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
268:in new' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 268:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
configurator.rb:282:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/ configurator.rb:281:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
configurator.rb:281:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/bin/mongrel_rails: 128:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
command.rb:212:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/bin/mongrel_rails: 281 c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:502:inload’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/
dependencies.rb:502:in load' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:354:innew_constants_in’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/
dependencies.rb:502:in load' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/ mongrel.rb:64 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:509:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/
dependencies.rb:354:in new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:509:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3

c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
attribute_methods.rb:251:in method_missing' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2361:insend’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2361:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2360:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
base.rb:2360:in attributes=' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ base.rb:2130:ininitialize’
app/controllers/public_controller.rb:28:in new' app/controllers/public_controller.rb:28:increate’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:1162:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:1162:inperform_action_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
filters.rb:580:in call_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:573:inperform_action_without_benchmark’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' c:/ruby/lib/ruby/1.8/benchmark.rb:293:inmeasure’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
benchmarking.rb:68:in perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ rescue.rb:201:inperform_action_without_caching’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
caching/sql_cache.rb:13:in perform_action' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/ connection_adapters/abstract/query_cache.rb:33:incache’
c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.1.0/lib/active_record/
query_cache.rb:8:in cache' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ caching/sql_cache.rb:12:inperform_action’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:529:in send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:529:inprocess_without_filters’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
filters.rb:569:in process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ session_management.rb:130:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:389:in process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:149:inhandle_request’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:107:in dispatch' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:104:insynchronize’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:104:in dispatch' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:120:indispatch_cgi’
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:35:in dispatch' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/ rails.rb:76:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
rails.rb:74:in synchronize' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/ rails.rb:74:inprocess’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
159:in process_client' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 158:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
158:in process_client' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 285:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
285:in initialize' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 285:innew’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
285:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 268:ininitialize’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb:
268:in new' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel.rb: 268:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
configurator.rb:282:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/ configurator.rb:281:ineach’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
configurator.rb:281:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/bin/mongrel_rails: 128:inrun’
c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/lib/mongrel/
command.rb:212:in run' c:/ruby/lib/ruby/gems/1.8/gems/mongrel-1.1.2-mswin32/bin/mongrel_rails: 281 c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:502:inload’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/
dependencies.rb:502:in load' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:354:innew_constants_in’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/
dependencies.rb:502:in load' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/servers/ mongrel.rb:64 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ingem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:509:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/
dependencies.rb:354:in new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.0/lib/active_support/ dependencies.rb:509:inrequire’
c:/ruby/lib/ruby/gems/1.8/gems/rails-2.1.0/lib/commands/server.rb:39
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3

Request

Parameters:

{“artist”=>[“Jack Johnson”],
“commit”=>“Create”,
“title”=>[“Sleep Through the Static”],
“authenticity_token”=>“ae4530b9c7db12cb6ae7d7326d44b2f7d0bdf3e4”,
“id”=>[“2”],
“genre”=>[“Beautiful”],
“release_date”=>{"(3i)"=>“1”,
“(4i)”=>“00”,
“(5i)”=>“00”,
“(1i)”=>“2008”,
“(2i)”=>“1”}}

Show session dump


:csrf_id: 4fe64497155d2f8d5dd1359e937beb49
flash: !map:ActionController::Flash::FlashHash {}

Response

Headers:

{“cookie”=>[],
“Cache-Control”=>“no-cache”}

On Jul 23, 12:19 am, A Love of Surf [email protected] wrote:

ok, so I am trying to learn the ‘c’ in crud from a tutorial right
now. Using the source below, I am loading the action ‘new’, filling
out a form to create a new record, and submitting the form to save the
record. The problem comes when I submit the form. The app generates
an error saying that the method commit= is not defined. At this
point, I don’t know enough about rails to extrapolate meaning from
this weirdness or to know what I should include in this request that’d
help someone to help me.

The short version is that there are parameters that are submitted that
don’t correspond to model attributes (eg the name of the button you
clicked), so when you give Artists.new your params hash there are some
keys it doesn’t know what to do with.

Id: <%= text_field(:id, @album.id) %>

You don’t need an edit field for id.
Artist: <%= text_field(:artist, @album.artist) %>

You’ve got the wrong pattern here. You should be doing
text_field ‘album’, ‘artist’
(and similarly for the other ones)
This tells rails 'I’m editing an album, and right now i’m looking at
the artist attribute.
This also makes what the user types appear as params[:album][:artist],
so instead of doing
Album.new params
you do
Album.new params[:album]
and since params[:album only contains what you put there you won’t get
the error message you got.
Fred

alright! thanks so much for the speedy and helpful answer. the only
thing that is more fun than ruby/rails is how awesome the community is
=]

On Jul 22, 4:27 pm, Frederick C. [email protected]

A Love of Surf wrote:

def create
@album = Album.new(params)

Until you learn to use form_for, or Hash#block, you must break out all
the
arguments to .new:

@album = Album.new(:artist => params[:artist],
:title => params[:title],
:etc => params[:etc])

Also, next time don’t worry about pasting the entire stack trace; it
just fills
up the servers, and we honestly won’t read a line of it!


Phlip

ok, i’m sorry about putting that huge text in my post.

but, i dont know what you mean about paste…i typed that

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs