I was considering writing a blog post about how I resolved the fields_for not displaying social profiles if the social_profile for that user had not yet been created. Unlike nonprofits, the social profile is not created at sign-up, so I couldn't use the build feature and handle this in the user registration controller. All of the solutions I found online suggested putting SocialProfile.new in the fields_for, i.e
<%= f.fields_for :social_profile, SocialProfile.new do |social_profile_form| %>
The problem with this solution is that once I create a path to one (or many) of the social networks, it will be overwritten the next time I go in to edit the profile. I thought a cleaner way was to conditionally create a new social profile only if one didn't exist yet, like this:
I figure someone else out there might have the same issue, but if there is a write up out there it isn't easy to find. Do you think the way I handled it is a good solution? And if so, do you think it's blog post worthy?
Eliot,
I was considering writing a blog post about how I resolved the
fields_for
not displaying social profiles if thesocial_profile
for that user had not yet been created. Unlike nonprofits, the social profile is not created at sign-up, so I couldn't use thebuild
feature and handle this in the user registration controller. All of the solutions I found online suggested puttingSocialProfile.new
in thefields_for
, i.eThe problem with this solution is that once I create a path to one (or many) of the social networks, it will be overwritten the next time I go in to edit the profile. I thought a cleaner way was to conditionally create a new social profile only if one didn't exist yet, like this:
I figure someone else out there might have the same issue, but if there is a write up out there it isn't easy to find. Do you think the way I handled it is a good solution? And if so, do you think it's blog post worthy?