Forum: Ruby on Rails form_for and virtual attribute

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.
Jason F. (Guest)
on 2007-07-05 17:40
I have an 'edit_user' template that looks like this:

    <% form_for :user, @user, :url => { :action => 'edit_user' } do |f|
%>
        <p>
            <label for="user_name">User Name:</label>
            <%= f.text_field :name %>
        <p>
            <label for="user_fullname">Full Name:</label>
            <%= f.text_field :fullname %>
        </p>
        <p>
            <label for="user_password">Password:</label>
            <%= f.text_field :password %>
        </p>
        <p>
            <label for="user_password_confirmation">Confirm:</label>
            <%= f.text_field :password_confirmation %>
        </p>
        <p>
            <label for="user_role">User Role:</label>
            <%= select_tag "user[role]", @options %>
        </p>


        <%= submit_tag "Save Changes", :class => "submit" %>
    <% end %>

The problem is that it never displays existing data for the password and
password_confirmation attributes.  Password is a virtual attribute that
actually points to a hashed_password in the db, as shown in the AWDWR
book.

This makes things difficult, because if I want to edit a user, I have to
know their existing password.

How do I get a virtual attribute to place it's value in the above
:password and :password_confirmation boxes?

Thanks!
This topic is locked and can not be replied to.