Skip to content

Instantly share code, notes, and snippets.

@h0lyalg0rithm
Last active September 13, 2015 17:58
Show Gist options
  • Save h0lyalg0rithm/9f375286813c07cf0c9a to your computer and use it in GitHub Desktop.
Save h0lyalg0rithm/9f375286813c07cf0c9a to your computer and use it in GitHub Desktop.
Devise Registration
.container
.row
.col-md-4.col-md-offset-4
.login-panel.panel.panel-default
.panel-heading
%h3.panel-title Sign up
.panel-body
%div
= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
= devise_error_messages!
%fieldset
.form-group
= f.label :name
= f.text_field :name, class: "form-control", autofocus: true
.form-group
= f.label :email
= f.email_field :email, class: "form-control", autofocus: true
.form-group
= f.label :password
- if @minimum_password_length
%em
(
= @minimum_password_length
characters minimum)
= f.password_field :password, class: "form-control", autocomplete: "off"
= f.label :password_confirmation
= f.password_field :password_confirmation, class: "form-control", autocomplete: "off"
.form-group
=f.fields_for :company do |c|
=c.label "Company Name"
=c.text_field :name, class: "form-control"
.actions
= f.submit "Sign up", class: "btn btn-lg btn-success btn-block"
%br
= render "users/shared/links"
class RegistrationsController < Devise::RegistrationsController
def new
build_resource({})
set_minimum_password_length
self.resource.company = Company.new
yield resource if block_given?
respond_with self.resource
end
def create
super
resource.update_attributes(role: :manager)
end
private
def sign_up_params
user_params = [:name, :email, :password, :password_confirmation, [company_attributes: [:name]]]
params.require(resource_name).permit(user_params)
end
end
Rails.application.routes.draw do
devise_for :users, path_names: { registration: 'register'}, controllers: { registrations: "registrations"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment