Skip to content

Instantly share code, notes, and snippets.

@universal
Forked from gbgdev/registration.html.erb
Last active January 19, 2016 13:49
Show Gist options
  • Save universal/dc1330a7b1a5cfc2dda5 to your computer and use it in GitHub Desktop.
Save universal/dc1330a7b1a5cfc2dda5 to your computer and use it in GitHub Desktop.
View Code
<%= form_for(resource, url: registration_path(resource_name), method: :post) do |f| %>
<%= f.fields_for :contacts do |contact_fields| %>
Nome: <%= contact_fields.text_field :name %>
<% 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
def contacts_attributes=(attributes)
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