Forum: Ruby on Rails I do not get it

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
E07ae8ce20cafb107abefa4a7fd326b6?d=identicon&s=25 Friedrich Dominicus (friedrich)
on 2006-03-11 15:18
How can I do the following. I have this list.rhtml page for

<%= form_tag ({:action => 'show_download_locations'}) %>

Please let us know who you are
<%= text_field("name", "",  :size =>20) %>
<%= submit_tag %>

<%= end_form_tag %>
a Postgres Database created with:
create table downloaders
       (id serial,
       name varchar(100),
       downloads integer);

This is the action which gets invoked:
  def show_download_locations
    name = params[:name]"name = #{name}")
    @downloader = Downloader.find(:first,
                                  :conditions => ["name = ?", name])

    if @downloader.nil?
      @downloader = = name
      @downloader.downloads = 1
      @downloader.downloads = @downloader.downloads + 1

    end!"@downloader id = #{}, name =
#{}, downloads = #{@downloader.downloads}")
    redirect_to :action => 'show', :id => @downloader

So you can see the only thing this is supposed to do is incrementing the
count of downloads from the user with name name.

I've populated the database by hand with a few values.
There's one test entry e.g

which yields:
 Name: test

Downloads: 6
Edit | Back

Fine this works
Now if I enter a name not yet there I got:
 Name: --- - foo

Downloads: 1

So I just put in foo but I got --- - foo in the field and this over and
over again.

The problem seems to be related with this
name = params[:name]

So what is the "right" thing to do to get something like this as output
Name: foo
Downloads: 1 ?

Thanks for any helping hand

E07ae8ce20cafb107abefa4a7fd326b6?d=identicon&s=25 Friedrich Dominicus (friedrich)
on 2006-03-12 08:20
Ok, I got it. params is a hash and this is a nested hash
the right thing is obvious
name = params[:downloader][:name]

This topic is locked and can not be replied to.