Guest User

Untitled

a guest
Jun 18th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class ContactsController < ApplicationController
  2. before_filter :find_contact, :only => [:show, :edit, :update, :destroy]
  3. permit "owner of contact or admin", :only => [:show, :edit, :update, :destroy]
  4.  
  5. # GET /contacts/1
  6. # GET /contacts/1.xml
  7. def show
  8. respond_to do |format|
  9. format.html # show.html.erb
  10. format.xml { render :xml => @contact }
  11. end
  12. end
  13.  
  14. # POST /contacts
  15. # POST /contacts.xml
  16. def create
  17. @contact = Contact.new(params[:contact])
  18. current_user.is_owner_of @contact
  19.  
  20. respond_to do |format|
  21. if @contact.save
  22. flash[:notice] = 'Contact was successfully created.'
  23. format.html { redirect_to(@contact) }
  24. format.xml { render :xml => @contact, :status => :created, :location => @contact }
  25. else
  26. format.html { render :action => "new" }
  27. format.xml { render :xml => @contact.errors, :status => :unprocessable_entity }
  28. end
  29. end
  30. end
  31. protected
  32. def find_contact
  33. @contact = Contact.find(params[:id])
  34. end
  35. end
Add Comment
Please, Sign In to add comment