Hi there,
I used restful authentication to generate the authenticated system,
but i still want to add a profile model as a part of user model.
So between user & profile I use has_one association to connect them.
Create - OK
But when i want to edit someone''s profile, the data not update in sql.
my user model is like this:
has_one :profile
attr_accessible :login, :email, :password, :password_confirmation
def profile_attributes=(profile_attributes)
profile_attributes do |attributes|
profile = profile.detect {|p| p.id == attributes[:id].to_i}
profile.attributes = attributes
end
end
My Profile model is like this:
belongs_to :user
The migration has the user_id foreign_key set up.
In the view/user/edit.html.erb, i wrote enclosed codes:
<% form_for :user, :url => user_url(@user), :html => { :method
=> :put } do |f| %>
<p>Email:<br /><%= f.text_field :email, :size => 60
%></p>
<% fields_for "user[profile_attributes][]", @user.profile do |
p_form| %>
<p>
Name: <%= p_form.text_field :name, :index => nil %>
</p>
<p>
Gender: <%= p_form.text_field :gender, :index => nil %>
</p>
<p>
Birthday: <%= p_form.text_field :birth_on, :index => nil %>
</p>
<p>
Place: <%= p_form.text_field :place, :index => nil %>
</p>
<p>
About Me: <%= p_form.text_field :about_me, :index => nil %>
</p>
<%= p_form.hidden_field :id, :index => nil %>
<% end %>
<%= submit_tag ''Update'' %>
<% end %>
When I click update button, error says: Couldn''t find Profile without
an ID
Or Can''t mass-assign in a protected attributes in the development log.
Can anyone help me?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Can anyone help me? *Barrier wrote:> Hi there, > > I used restful authentication to generate the authenticated system, > but i still want to add a profile model as a part of user model. > > So between user & profile I use has_one association to connect them. > > Create - OK > But when i want to edit someone''s profile, the data not update in sql. > > my user model is like this: > > has_one :profile > attr_accessible :login, :email, :password, :password_confirmation > > def profile_attributes=(profile_attributes) > profile_attributes do |attributes| > profile = profile.detect {|p| p.id == attributes[:id].to_i} > profile.attributes = attributes > end > end > > My Profile model is like this: > belongs_to :user > > The migration has the user_id foreign_key set up. > > In the view/user/edit.html.erb, i wrote enclosed codes: > > > <% form_for :user, :url => user_url(@user), :html => { :method > => :put } do |f| %> > <p>Email:<br /><%= f.text_field :email, :size => 60 %></p> > <% fields_for "user[profile_attributes][]", @user.profile do | > p_form| %> > <p> > Name: <%= p_form.text_field :name, :index => nil %> > </p> > <p> > Gender: <%= p_form.text_field :gender, :index => nil %> > </p> > <p> > Birthday: <%= p_form.text_field :birth_on, :index => nil %> > </p> > <p> > Place: <%= p_form.text_field :place, :index => nil %> > </p> > <p> > About Me: <%= p_form.text_field :about_me, :index => nil %> > </p> > <%= p_form.hidden_field :id, :index => nil %> > <% end %> > > <%= submit_tag ''Update'' %> > <% end %> > > When I click update button, error says: Couldn''t find Profile without > an ID > > Or Can''t mass-assign in a protected attributes in the development log. > > Can anyone help me?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7/2/08, *Barrier <developer-Tg192j3TZ/7QT0dZR+AlfA@public.gmane.org> wrote:> > Can anyone help me?You need to iterate through the hash: profile_attributes do |attributes| Change to: profile_attributes.each do |attributes| Also, be sure to save the profile model. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---