Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person < ActiveRecord::Base
- validates :terms_of_service, acceptance: { accept: 'yes' }
- end
- class UsersController < ApplicationController
- before_filter :authenticate_user!
- before_filter :admin_only, :except => :show
- def index
- @users = User.all
- end
- def show
- @user = User.find(params[:id])
- unless current_user.admin?
- unless @user == current_user
- redirect_to :back, :alert => "Access denied."
- end
- end
- end
- def update
- @user = User.find(params[:id])
- if @user.update_attributes(secure_params)
- redirect_to users_path, :notice => "User updated."
- else
- redirect_to users_path, :alert => "Unable to update user."
- end
- end
- def destroy
- user = User.find(params[:id])
- user.destroy
- redirect_to users_path, :notice => "User deleted."
- end
- private
- def user_params
- params.require(:user).permit(:name, :email, :terms_accepted)
- end
- def admin_only
- unless current_user.admin?
- redirect_to :back, :alert => "Access denied."
- end
- end
- def secure_params
- params.require(:user).permit(:role)
- end
- end
- ---
- class User < ActiveRecord::Base
- validates :terms_accepted, acceptance: { accept: 'yes' }
- enum role: [:user, :vip, :admin]
- after_initialize :set_default_role, :if => :new_record?
- def set_default_role
- self.role ||= :user
- end
- # Include default devise modules. Others available are:
- # :confirmable, :lockable, :timeoutable and :omniauthable
- devise :invitable, :database_authenticatable, :registerable, :confirmable,
- :recoverable, :rememberable, :trackable, :validatable
- end
- ---
- <div class="row">
- <div class="col-md-6">
- <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :role => 'form'}) do |f| %>
- <h2 class="form-signin-heading">Sign Up</h2>
- <%= devise_error_messages! %>
- <div class="form-group">
- <%= f.label :name %>
- <%= f.text_field :name, :autofocus => true, class: 'form-control' %>
- </div>
- <div class="form-group">
- <%= f.label :email %>
- <%= f.email_field :email, class: 'form-control' %>
- </div>
- <div class="form-group">
- <%= f.label :password %>
- <%= f.password_field :password, class: 'form-control' %>
- </div>
- <div class="form-group">
- <%= f.label :confirm_password %>
- <%= f.password_field :password_confirmation, class: 'form-control' %>
- </div>
- <div class="form-group">
- <%= f.check_box :terms_accepted%>
- <%= f.label :accept_terms %>
- <%= link_to 'Terms Of Use', '/TermsOfUse.html', :target => "_blank" %>
- </div>
- <div class="form-group">
- <%= f.submit 'Sign Up', :class => 'btn btn-lg btn-login' %>
- </div>
- <div class="form-group">
- <%= render "devise/shared/links" %>
- </div>
- <% end %>
- </div>
- Started GET "/" for ::1 at 2015-06-29 13:55:55 -0700
- Processing by VisitorsController#index as HTML
- (0.5ms) SELECT COUNT(*) FROM "users"
- Rendered visitors/index.html.erb within layouts/application (1.6ms)
- Rendered layouts/_flatlabnavbartop.html.haml (16.2ms)
- Completed 200 OK in 347ms (Views: 345.7ms | ActiveRecord: 0.5ms)
- Started GET "/users/sign_up" for ::1 at 2015-06-29 13:56:00 -0700
- Processing by DeviseInvitable::RegistrationsController#new as HTML
- Rendered /usr/local/rvm/gems/ruby-2.2.1@suits6/gems/devise-3.4.1/app/views/devise/shared/_links.html.erb (1.4ms)
- Rendered devise/registrations/new.html.erb within layouts/application (51.9ms)
- Rendered layouts/_flatlabnavbartop.html.haml (1.9ms)
- Completed 200 OK in 279ms (Views: 277.9ms | ActiveRecord: 0.0ms)
- Started POST "/users" for ::1 at 2015-06-29 13:56:29 -0700
- Processing by DeviseInvitable::RegistrationsController#create as HTML
- Parameters: {"utf8"=>"✓", "authenticity_token"=>"4t0UPaQhI/0HcsqC3RkBrcWQWjhWzKojZLvrMloObPSAiapVc46bvxT5TGePh4v2IUCi8QbdVuMWuQsyzyFmdg==", "user"=>{"name"=>"Maude Username", "email"=>"maude@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "terms_accepted"=>"1"}, "commit"=>"Sign Up"}
- Unpermitted parameter: terms_accepted
- User Load (119.8ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 AND "users"."encrypted_password" = $2 ORDER BY "users"."id" ASC LIMIT 1 [["email", "maude@gmail.com"], ["encrypted_password", ""]]
- (0.2ms) BEGIN
- User Exists (16.6ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'maude@gmail.com' LIMIT 1
- (8.3ms) ROLLBACK
- Rendered /usr/local/rvm/gems/ruby-2.2.1@suits6/gems/devise-3.4.1/app/views/devise/shared/_links.html.erb (0.7ms)
- Rendered devise/registrations/new.html.erb within layouts/application (18.5ms)
- Rendered layouts/_flatlabnavbartop.html.haml (2.9ms)
- Completed 200 OK in 733ms (Views: 383.5ms | ActiveRecord: 144.9ms)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement