admin adds new user/person and registration
This commit is contained in:
parent
7e43a00098
commit
d2709f0570
4 changed files with 58 additions and 0 deletions
|
|
@ -16,4 +16,44 @@ class Admin::UsersController < ApplicationController
|
|||
user.update_attributes!(params[:user])
|
||||
redirect_to admin_users_path, :notice => "Updated #{user.email}"
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
@person = Person.where("user_id =?", @user.id)
|
||||
@conferences = Conference.where("end_date >= ?", Time.now)
|
||||
@conference = Conference.find_all_by_short_title(params[:format]).first
|
||||
end
|
||||
|
||||
def create
|
||||
@conference = Conference.find_all_by_short_title(params[:id]).first
|
||||
|
||||
if params[:user][:people][:first_name].blank? || params[:user][:people][:last_name].blank?
|
||||
redirect_to(:back, :alert => "Please fill in your first and last name before registering.")
|
||||
return
|
||||
end
|
||||
|
||||
params[:user][:conferences].shift
|
||||
if !params[:user][:conferences].empty?
|
||||
user = User.new
|
||||
user.email = params[:user][:email]
|
||||
user.password = params[:user][:password]
|
||||
begin
|
||||
user.save!
|
||||
user.skip_confirmation!
|
||||
person = Person.where("user_id = ?", user.id).first
|
||||
person.update_attributes(params[:user][:people])
|
||||
redirect_to admin_conference_registrations_path(@conference.short_title)
|
||||
flash[:notice] = "Successfully created new registration for #{person.email}."
|
||||
rescue Exception => e
|
||||
redirect_to(:back, :alert => e.message)
|
||||
return
|
||||
end
|
||||
params[:user][:conferences].each do |r|
|
||||
registration = person.registrations.new(:conference_id => r)
|
||||
registration.save!
|
||||
end
|
||||
else
|
||||
redirect_to(:back, :alert => "Please select at least one conference to register.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
.row-fluid
|
||||
.span12
|
||||
.pull-right{:style=>"margin-top:20px; margin-bottom:20px;"}
|
||||
= link_to "New", admin_users_new_path(@conference.short_title), :class => "btn btn-primary"
|
||||
= link_to "Export PDF", admin_conference_registrations_path(@conference.short_title, :format => :pdf), :class => "btn btn-success"
|
||||
.row-fluid
|
||||
.span12
|
||||
|
|
|
|||
16
app/views/admin/users/new.html.haml
Normal file
16
app/views/admin/users/new.html.haml
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
.row
|
||||
.span12
|
||||
%h3
|
||||
Create new account and registration
|
||||
.row
|
||||
.span12
|
||||
= semantic_form_for(@user, :url => admin_users_new_path(:id => @conference.short_title), :html => { :method => :put }) do |f|
|
||||
= f.inputs "Account Information" do
|
||||
= f.input :email
|
||||
= f.input :password, :hint => "Password must be at least 6 characters"
|
||||
= f.inputs "Personal Information" do
|
||||
= f.fields_for :people do |p|
|
||||
= p.input :first_name
|
||||
= p.input :last_name
|
||||
= f.input :conferences, :as => :check_boxes, :label => true, :collection => @conferences
|
||||
= f.action :submit, :button_html => { :value => "Create", :class => "btn btn-primary"}
|
||||
|
|
@ -3,6 +3,7 @@ Osem::Application.routes.draw do
|
|||
devise_for :users, :controllers => { :registrations => :registrations }, :path => 'accounts'
|
||||
|
||||
namespace :admin do
|
||||
put "/users/new" => "users#create"
|
||||
resources :users
|
||||
resources :people
|
||||
resources :conference do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue