[Nitro] Help with form_to_

Ed Chang localuser at gmail.com
Thu Nov 23 10:48:28 EST 2006


Thanks for your help Jonathan - it's good to get some direction when
one feels like he is groping in the dark. I'd appreciate some
additional help from anyone that's interested in getting step 6 of the
Nitro tutorial to work.

I've modified controller.rb by adding the following method as Jonathan
described in a previous email:

    def update()
        user = User.find_or_create_by_name(request['name'])
        request.fill(user)
        user.save
        redirect_to R(:list)
    end #update

After that change, this URL
http://localhost:9000/update?oid=1&name=Terry+Tate&description=Footballer&age=32
produces the following error message:

Error
Path: /update
Wrong parameter count for update().
Reload this page. Go to the referer or the home page.
In file '(eval)' :

Stack Trace
(eval):28:in `update_action'
...

Hmm, wrong parameter count...so I modify the update method to look
like the following:

  def update( oid, name, description, age )

Unfortunately, this too generates an error message:

Error
Path: /update
near " ": syntax error
Reload this page. Go to the referer or the home page.
In file 'C:/Ruby/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.1.0.1-mswin32/lib/sqlite3/errors.rb'
:

Now I wonder if I'm calling the correct method to save a new user. I
grep the Nitro directory for find_or_create_by_name and find that only
the Tag class uses this method. Looks like I should instead, be using
User.find_or_create_by_name_and_age.

I'm confused. At this point, help is much appreciated.

Ed


On 11/22/06, Jonathan Buch <john at oxyliquit.de> wrote:
> Hi,
>
> >   #{form(:object => User, :action => :find_by_name) do |f|
> >         f.attributes
> >         f.submit 'Save'
> >     end}
> >
> > Now the page is displayed in the browser, but the following error is displayed:
> >
> >   Path: /find_by_name
> >   No action for path '/find_by_name' on 'Hello'
>
> I assume the form appeared as expected on the first page?
>
> The translation you did from form_for() to form() is slightly incorrect.
>
> #{form_for User.find_by_name( @name )}
> #{form(:object => User.find_by_name(@name), :action => :update) do |f|
>   f.attributes
>         f.submit 'Save'
> end}
>
> The :action is the method which will be called when you press the submit
> button.  You then need to handle the request:
>
> def update
>   user = User.find_or_create_by_name(request['name'])
>         request.fill(user)
>         user.save
>         redirect_to R(:list)
> end
>
> Or at least something along these lines.  I haven't actually tested
> this but it should work just like this.
>
> Hope this helps,
>
> Jonathan
>
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>


More information about the Nitro-general mailing list