Skip to content

Instantly share code, notes, and snippets.

@gbgdev
Last active January 19, 2016 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gbgdev/4b0431f1281501623b6b to your computer and use it in GitHub Desktop.
Save gbgdev/4b0431f1281501623b6b to your computer and use it in GitHub Desktop.
View Code
<%= form_for(resource, url: registration_path(resource_name), method: :post) do |f| %>
<% resource.contacts.each do |contact| %>
<% f.fields_for :contact do |contact_fields| %>
Nome: <%= contact_fields.text_field :name %>
<% end %>
<% end %>
<div class="register-buttons">
<%= f.submit "Finish", class: "button button-primary", data: { disable_with: "Finish" } %>
</div>
<% end %>
class Registration
include ActiveModel::Model
attr_accessor :contacts
def initialize(customer, params = {})
@contacts = [Contact.new, Contact.new]
@customer = customer
super(params)
end
end
end
class RegistrationsController < Devise::RegistrationsController
prepend_before_filter :authenticate_scope!, only: [:edit, :update, :destroy, :success_sign_up]
def new; end
def create
@resource = Registration.new(customer, params)
end
def resource
@resource ||= Registration.new(customer)
end
def success_sign_up; end
# overriding sign up to work with form object instead directly with model
def sign_up(resource_name, resource)
sign_in(resource_name, resource.customer)
end
private
def customer
current_customer || Customer.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment