Class: ContactsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ContactsController
- Defined in:
- app/controllers/contacts_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #pending ⇒ Object
-
#suggestion ⇒ Object
Return a suggestion for this contact.
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/contacts_controller.rb', line 23 def create relation_ids = params[:relations].map(&:to_i) params[:actors].split(',').each do |a| c = profile_or_current_subject.contact_to!(a) # Record who is manipulating the contact, mainly in groups c. = current_user c.relation_ids = relation_ids end flash[:success] = t "contact.new.added.other", actors: params[:actors].split(',').map{ |a| Actor.find(a).name }.to_sentence, relations: relation_ids.map{ |r| Relation.find(r).name }.to_sentence redirect_to request.referrer || { action: :index } end |
#destroy ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/controllers/contacts_controller.rb', line 63 def destroy relation_ids = [] if params[:reject].present? relation_ids << Relation::Reject.instance.id end @contact.relation_ids = [] respond_to do |format| format.js end end |
#index ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/controllers/contacts_controller.rb', line 10 def index params[:subject] = subject = profile_or_current_subject! params[:d] ||= 'sent' params[:type] ||= subject.class.contact_index_models.first.to_s @contacts = Contact.index(params) respond_to do |format| format.html { render current_subject_contacts_to(@contacts) if request.xhr? } format.json { render json: @contacts.map(&:receiver), helper: self } end end |
#pending ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'app/controllers/contacts_controller.rb', line 87 def pending @contact = current_subject.pending_contacts.last respond_to do |format| format.html { @contact.present? ? render(partial: @contact) : render(text: "") } format.json { render json: @contact } end end |
#suggestion ⇒ Object
Return a suggestion for this contact
78 79 80 81 82 83 84 85 |
# File 'app/controllers/contacts_controller.rb', line 78 def suggestion @contact = current_subject.suggestions.first respond_to do |format| format.html { @contact.present? ? render(partial: @contact) : render(text: "") } format.json { render json: @contact } end end |
#update ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/controllers/contacts_controller.rb', line 40 def update # Record who is manipulating the contact, mainly in groups @contact. = current_user # FIXME: This should be in the model params[:contact][:relation_ids].present? && params[:contact][:relation_ids].delete("0") @contact.update_attributes(params[:contact]) respond_to do |format| format.html { if @contact.errors.blank? redirect_to @contact.receiver_subject else render :action => 'edit' end } format.js end end |