I'm new to Rails and i'm trying to create a 'nested' form for user to
a company. I would like the client to be able to create a company in
the users sign up form. I get the part were you can choose a company
from a collection, but i want to allow the user to create a new
company through a text field in the sign up user form.
This is what i have:
class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :admin, :company_id, :firstname, :lastname
class Company < ActiveRecord::Base
and in the form:
<%= simple_form_for(resource, :as => resource_name, :url =>
registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<%= f.fields_for :company do |cf| %>
<%= cf.input :name, :required => true, :autofocus => true %>
<% end %>
<%= f.input :email, :required => true, :autofocus => true %>
<%= f.input :password, :required => true %>
<%= f.input :password_confirmation, :required => true %>
<%= f.button :submit, :class => 'btn-primary', :value => 'Sign up'
<% end %>
The above code gives a company name text field in the form but on
submit rails trows an error: Can't mass-assign protected attributes:
company. I probably have to add a route to? until now i only have
resources :companies and resources :users.
I did my best to google for a solution/ example.. found some nested
form examples but its not clear to me.
Any help on this would be appreciated.
Thanks in advance!
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 email@example.com.
To unsubscribe from this group, send email to firstname.lastname@example.org.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.