Note that there are some explanatory texts on larger screens.

plurals
  1. PODevise user sign up form with business model
    primarykey
    data
    text
    <p>I'm trying to create a user sign up form with Devise that will also allow for the creation of a new business associated with that user.</p> <p>I have a business model setup and can't seem to save the business information to the database. Below is my code, I'm fairly new to rails so I apologize if I'm asking a question with an obvious answer.</p> <p>new.html.erb (user)</p> <pre><code>&lt;div class="content"&gt; &lt;div class="row"&gt; &lt;div class="col-md-6 col-md-offset-3"&gt; &lt;h1&gt;Sign Up&lt;/h1&gt; &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt; &lt;%= devise_error_messages! %&gt; &lt;div class="form-group"&gt; &lt;label&gt;Name&lt;/label&gt; &lt;%= f.text_field :username, :autofocus =&gt; true, :class =&gt; "form-control", :placeholder =&gt; "Full Name" %&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;%= f.label :email %&gt; &lt;%= f.text_field :email, :class =&gt; "form-control", :placeholder =&gt; "Email" %&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;%= f.label :password %&gt; &lt;%= f.password_field :password, :class =&gt; "form-control", :placeholder =&gt; "Password" %&gt; &lt;p class="help-block"&gt;Passwords must be a minimum of 8 characters.&lt;/p&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;%= f.label :password_confirmation %&gt; &lt;%= f.password_field :password_confirmation, :class =&gt; "form-control", :placeholder =&gt; "Retype Password" %&gt; &lt;/div&gt; &lt;!-- Business Infomation --&gt; &lt;h2&gt;Business Information&lt;/h2&gt; &lt;%= f.fields_for :business do |b| %&gt; &lt;div class="form-group"&gt; &lt;%= b.label :name %&gt; &lt;%= b.text_field :name, :class =&gt; "form-control", :placeholder =&gt; "Business Name" %&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;%= b.label :address %&gt; &lt;%= b.text_field :address, :class =&gt; "form-control", :placeholder =&gt; "Address" %&gt; &lt;/div&gt; &lt;div class="row"&gt; &lt;div class="col-sm-6"&gt; &lt;div class="form-group"&gt; &lt;%= b.label :city %&gt; &lt;%= b.text_field :city, :class =&gt; "form-control", :placeholder =&gt; "City" %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="col-sm-2"&gt; &lt;div class="form-group"&gt; &lt;%= b.label :state %&gt; &lt;%= b.text_field :state, :class =&gt; "form-control", :placeholder =&gt; "State" %&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="col-sm-4"&gt; &lt;div class="form-group"&gt; &lt;%= b.label :zip %&gt; &lt;%= b.text_field :zip, :class =&gt; "form-control", :placeholder =&gt; "ZIP" %&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="form-group"&gt; &lt;%= b.label :country %&gt; &lt;%= b.text_field :country, :class =&gt; "form-control", :placeholder =&gt; "Country" %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;div class="well"&gt; &lt;%= f.submit "Sign Up", :class =&gt; "btn btn-primary" %&gt; &lt;/div&gt; &lt;% end %&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <p>user.rb</p> <pre><code>class User include Mongoid::Document include Mongoid::Paperclip rolify include Mongoid::Timestamps #embeds_many :businesses, :class_name =&gt; "Business" # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or protected) attributes for your model attr_accessible :role_ids, :as =&gt; :admin attr_accessible :username, :email, :password, :password_confirmation, :remember_me, :business_ids, :reset_password_sent_at, :reset_password_within, :address, :city, :state, :zip, :country, :phone, :business_attributes has_one :businesses accepts_nested_attributes_for :businesses validates_format_of :email, :with=&gt;email_regexp, :allow_blank =&gt; true, :message=&gt; "Justin" #intercom attr_accessor :company_name attr_accessible :company_name ## Database authenticatable field :email, :type =&gt; String, :default =&gt; "" field :encrypted_password, :type =&gt; String, :default =&gt; "" ## Recoverable field :reset_password_token, :type =&gt; String #field :reset_password_sent_at, :type =&gt; Time field :reset_password_sent_at, :type =&gt; Time ## Rememberable field :remember_created_at, :type =&gt; Time #field :remember_created_at, :type =&gt; String ## Trackable field :username, :type =&gt; String field :sign_in_count, :type =&gt; Integer, :default =&gt; 0 #field :current_sign_in_at, :type =&gt; Time #field :last_sign_in_at, :type =&gt; Time field :current_sign_in_at, :type =&gt; Time field :last_sign_in_at, :type =&gt; Time field :current_sign_in_ip, :type =&gt; String field :last_sign_in_ip, :type =&gt; String field :first_name, :type =&gt; String field :last_name, :type =&gt; String #field :business_ids, :type =&gt; Array field :address, :type =&gt; String field :city, :type =&gt; String field :state, :type =&gt; String field :zip, :type =&gt; String field :country, :type =&gt; String field :phone, :type =&gt; String # User Avatar attr_accessible :avatar has_mongoid_attached_file :avatar, :styles =&gt; { :full =&gt; ["512x512&gt;", :jpg], :medium =&gt; ["256x256&gt;", :jpg] }, :convert_options =&gt; {:medium =&gt; "-background black -gravity center -extent 256x256"}, :default_url =&gt; "/assets/avatar-blank.png" validates_attachment_size :avatar, :less_than =&gt; 5.megabytes validates_attachment_content_type :avatar, :content_type =&gt; ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] ## Confirmable # field :confirmation_token, :type =&gt; String # field :confirmed_at, :type =&gt; Time # field :confirmation_sent_at, :type =&gt; Time # field :unconfirmed_email, :type =&gt; String # Only if using reconfirmable ## Lockable # field :failed_attempts, :type =&gt; Integer, :default =&gt; 0 # Only if lock strategy is :failed_attempts # field :unlock_token, :type =&gt; String # Only if unlock strategy is :email or :both # field :locked_at, :type =&gt; Time ## Token authenticatable # field :authentication_token, :type =&gt; String after_create :create_business def create_business Business.create(business_id: self.id) end def assign_default_role(b) # assign a default role if no role is assigned # IF, invite token make user an editor for business # ELSE, make the user owner of the business self.add_role "owner", b end #Returns a businesses for a user. The return type is an array of Business models. def businesses Business.find(get_business_ids) end #returns the user business_ids (Array of Strings) def get_business_ids Business.find_roles(nil, self).map{|b| b.resource_id.to_s}.to_a end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload