Customizing signup form adding fields from Profile

35 views
Skip to first unread message

Matthew Simpson

unread,
Jul 17, 2013, 3:28:21 PM7/17/13
to social...@googlegroups.com
Hi fellow Social Streamers -

I'm currently trying to customize the signup form (views/devise/registrations/new.html.erb). What I want to do is add a couple of fields which belong to the Profile. Now this form is for User, User includes Subject, and Subject accepts_nested_attributes_for Profile. So I was thinking I could just use fields_for in the view and add my profile fields there and it would all Just Work. Something like this inside the form_for:
     
<%= f.fields_for :profile do |ff| %>
  <%= ff.label :country %>
  <%= ff.text_field :country %>
<% end %>

However, the nested fields are not rendered. I thought I might need to set up a blank new Profile so I tried adding the following code before the form_for:

<%
  resource.actor ||= Actor.new
  resource.actor.profile ||= Profile.new
%>

But that didn't make any difference. Does anybody have any idea what I'm doing wrong and how I can add profile fields to the signup form?

Antonio Tapiador del Dujo

unread,
Jul 22, 2013, 10:30:04 AM7/22/13
to social...@googlegroups.com
Hi Matthew, it will be probably a problem related to attr_accessible attributes in the user model:

https://github.com/ging/social_stream/blob/master/base/app/models/user.rb#L23

However, in my experience, I find easier delegating the fields from the user/actor to the profile model that struggling with nested attributes, which is quite powerful but a bit complex.

You can find an example of this in the ViSH's code, in the other direction (delegate from profile to the user model):

https://github.com/ging/vish/blob/master/app/decorators/profile_decorator.rb

El 17/07/13 21:28, Matthew Simpson escribió:
--
You received this message because you are subscribed to the Google Groups "Social Stream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to social-strea...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Matthew Simpson

unread,
Jul 23, 2013, 5:31:37 AM7/23/13
to social...@googlegroups.com
Thanks Antonio, in the end I actually re-architected so this wasn't needed. But I will be displaying Actor fields on the Profile form so the example you gave will be helpful.

Yasir Hashmi

unread,
Jun 5, 2014, 12:27:06 PM6/5/14
to social...@googlegroups.com
I have a same question but example is removed
Reply all
Reply to author
Forward
0 new messages