Class: PeopleController
- Inherits:
-
ArtfullyOseController
- Object
- ActionController::Base
- ArtfullyOseController
- PeopleController
- Defined in:
- app/controllers/people_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #star ⇒ Object
- #tag ⇒ Object
- #untag ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/people_controller.rb', line 10 def create :create, Person @person = Person.new person = params[:person] @person.first_name = person[:first_name] unless person[:first_name].blank? @person.last_name = person[:last_name] unless person[:last_name].blank? @person.email = person[:email] unless person[:email].blank? @person.subscribed_lists = person[:subscribed_lists] unless person[:subscribed_lists].blank? @person.do_not_email = person[:do_not_email] unless person[:do_not_email].blank? @person.organization_id = current_user.current_organization.id if @person.valid? && @person.save! @person.create_subscribed_lists_notes!(current_user) respond_to do |format| format.html do redirect_to person_url(@person) end format.json do render :json => @person.as_json end end else respond_to do |format| format.html do render :new end format.json do render :json => @person.as_json.merge(:errors => @person.errors.), :status => 400 end end end end |
#edit ⇒ Object
114 115 116 117 |
# File 'app/controllers/people_controller.rb', line 114 def edit @person = Person.find(params[:id]) :edit, @person end |
#index ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'app/controllers/people_controller.rb', line 77 def index :manage, Person @people = [] if is_search(params) @people = Person.search_index(params[:search].dup, current_user.current_organization) respond_with do |format| format.csv { render :csv => @people, :filename => "SearchResults-#{DateTime.now.strftime("%m-%d-%y")}.csv" } format.html { render :partial => 'list', :layout => false, :locals => { :people => @people } if request.xhr? } format.json { render :json => @people } end else @people = Person.recent(current_user.current_organization) end @people = @people.paginate(:page => params[:page], :per_page => 20) end |
#new ⇒ Object
5 6 7 8 |
# File 'app/controllers/people_controller.rb', line 5 def new :create, Person @person = Person.new end |
#show ⇒ Object
95 96 97 98 99 |
# File 'app/controllers/people_controller.rb', line 95 def show @person = Person.find(params[:id]) @orders = Order.where(:person_id => @person.id).includes(:person, :actions, :items).order(:created_at).paginate(:page => params[:page], :per_page => 25) :view, @person end |
#star ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/people_controller.rb', line 101 def star render :nothing => true type = params[:type] starable = Action.find(params[:action_id]) if starable.starred? starable.starred = false else starable.starred = true end starable.save end |
#tag ⇒ Object
119 120 121 122 123 124 125 |
# File 'app/controllers/people_controller.rb', line 119 def tag @person = Person.find(params[:id]) :edit, @person @person.tag_list << params[:tag] @person.save render :nothing => true end |
#untag ⇒ Object
127 128 129 130 131 132 133 |
# File 'app/controllers/people_controller.rb', line 127 def untag @person = Person.find(params[:id]) :edit, @person @person.tag_list.remove(params[:tag]) @person.save render :nothing => true end |
#update ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/people_controller.rb', line 47 def update @person = Person.find(params[:id]) :edit, @person results = @person.update_attributes(params[:person]) respond_to do |format| format.html do if results @person.create_subscribed_lists_notes!(current_user) flash[:notice] = "Your changes have been saved" @person = Person.find(params[:id]) redirect_to person_url(@person) else flash[:alert] = "Sorry, we couldn't save your changes. Make sure you entered a first name, last name or email address." render :edit end end format.json do if results render :json => @person else render :nothing => true end end end end |