Forum: Ruby on Rails I do not get it

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community 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'}) %>



<p>
Please let us know who you are
</p>
<%= 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]
    logger.info("name = #{name}")
    @downloader = Downloader.find(:first,
                                  :conditions => ["name = ?", name])

    if @downloader.nil?
      @downloader = Downloader.new()
      @downloader.name = name
      @downloader.downloads = 1
    else
      @downloader.downloads = @downloader.downloads + 1

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


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

Regards
Friedrich
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]

Regards
Friedrich
This topic is locked and can not be replied to.