Forum: Ruby on Rails Forms fields pre-populating w/ first record's values

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.
8d4c3605bb2853f5088f8719d352f3cd?d=identicon&s=25 Clem Rock (clemrock)
on 2008-12-31 03:00
I have a strange situation.    I want to have a create_user form w/ all
the fields blank

When I call the create_user method, the corresponding
create_user.html.erb form is displaying the first
record's data from the user table in the form fields

Here's a quick view of my form:

[code]
<% form_tag('create_user') do -%>
   <%=hidden_field("user", "id") %> (<%=params[:id] %>)
   <p><label for="fname">First Name</label><br/>
    <%=text_field("user", "fname") %></p>

   <p><label for="lname">Last Name</label><br/>
    <%=text_field("user", "lname") %></p>
  <%=submit_tag("Create") %>
<% end -%>

[/code]

When that form loads, it is populated w/ the First and last name from
the first user record in the db.

Anyway around this - I've tried everything I can think of.

Thanks,
Clem
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2008-12-31 03:35
(Received via mailing list)
form_tag does not tag a string as an argument.

Could you show us your controller please?

Also, it may help you if you read
http://guides.rubyonrails.org/getting_started_with...
  first.
-----
Ryan Bigg
Freelancer
http://frozenplague.net
8d4c3605bb2853f5088f8719d352f3cd?d=identicon&s=25 Clem Rock (clemrock)
on 2008-12-31 05:46
Thanks for getting back to me on this.

Here's my controller method:

def create_user
    if request.post?
      @user = User.new(params[:user])
      if @user.save
        flash[:notice] = "User has been added."
        flash.keep
        redirect_to :controller => 'admin', :action => 'list_users', :id
=> @user.id, :page => params[:page]
      end
    end
  end


Thanks again

Ryan Bigg wrote:
> form_tag does not tag a string as an argument.
>
> Could you show us your controller please?
>
> Also, it may help you if you read
> http://guides.rubyonrails.org/getting_started_with...
>   first.
> -----
> Ryan Bigg
> Freelancer
> http://frozenplague.net
8d4c3605bb2853f5088f8719d352f3cd?d=identicon&s=25 Clem Rock (clemrock)
on 2009-01-10 21:26
Problem solved: all I had to do was to add Address.new in the
controller.

Newbies





Clem Rock wrote:
> Thanks for getting back to me on this.
>
> Here's my controller method:
>
> def create_user
>     if request.post?
>       @user = User.new(params[:user])
>       if @user.save
>         flash[:notice] = "User has been added."
>         flash.keep
>         redirect_to :controller => 'admin', :action => 'list_users', :id
> => @user.id, :page => params[:page]
>       end
>     end
>   end
>
>
> Thanks again
>
> Ryan Bigg wrote:
>> form_tag does not tag a string as an argument.
>>
>> Could you show us your controller please?
>>
>> Also, it may help you if you read
>> http://guides.rubyonrails.org/getting_started_with...
>>   first.
>> -----
>> Ryan Bigg
>> Freelancer
>> http://frozenplague.net
This topic is locked and can not be replied to.