A Love of Surf | 23 Jul 01:19

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
(Continue reading)

Frederick Cheung | 23 Jul 01:27

Re: Can someone please help a very eager Rails newbie?


On Jul 23, 12:19 am, A Love of Surf <wetl...@...> 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) %><br />
You don't need an edit field for id.
>   Artist: <%= text_field(:artist, @album.artist) %><br />

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]
(Continue reading)

A Love of Surf | 23 Jul 01:39

Re: Can someone please help a very eager Rails newbie?


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 Cheung <frederick.che...@...>
wrote:
> On Jul 23, 12:19 am, A Love of Surf <wetl...@...> 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) %><br />
>
> You don't need an edit field for id.
>
> >   Artist: <%= text_field(:artist, @album.artist) %><br />
>
> You've got the wrong pattern here. You should be doing
(Continue reading)

Phlip | 23 Jul 03:09

Re: Can someone please help a very eager Rails newbie?


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

--~--~---------~--~----~------------~-------~--~----~
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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@...
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

A Love of Surf | 23 Jul 03:14

Re: Can someone please help a very eager Rails newbie?


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

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

On Jul 22, 6:09 pm, Phlip <phlip2...@...> wrote:
> 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
--~--~---------~--~----~------------~-------~--~----~
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@...
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe <at> googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

(Continue reading)


Gmane