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