Class: Gemgento::User::AddressesController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- Gemgento::User::AddressesController
- Defined in:
- app/controllers/gemgento/user/addresses_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 23 def create @address = Gemgento::Address.new(address_params) @address.addressable = current_user @address.sync_needed = true respond_to do |format| if @address.save format.html { redirect_to user_addresses_path, notice: 'The address has been added successfully.' } format.json { render json: { result: true, address: @address } } else format.html { render 'new' } format.json { render json: { result: false, errors: @address.errors. } } end end end |
#destroy ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 56 def destroy @address = current_user.addresses.find(params[:id]) respond_to do |format| if @address.destroy format.html { redirect_to user_addresses_path, notice: 'The address has been deleted from your address book.' } format.json { render json: { result: true } } else format.html { redirect_to user_addresses_path, alert: 'The address could not be destroyed.' } format.json { render json: { result: false, errors: @address.errors. } } end end end |
#edit ⇒ Object
18 19 20 21 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 18 def edit @address = current_user.addresses.find(params[:id]) respond_with @address end |
#index ⇒ Object
4 5 6 7 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 4 def index @addresses = current_user.addresses respond_with @addresses end |
#new ⇒ Object
14 15 16 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 14 def new @address = Gemgento::Address.new end |
#show ⇒ Object
9 10 11 12 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 9 def show @address = current_user.address_book.find(params[:id]) respond_with @address end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/gemgento/user/addresses_controller.rb', line 41 def update @address = current_user.addresses.find(params[:id]) @address.sync_needed = true respond_to do |format| if @address.update_attributes(address_params) format.html { redirect_to user_addresses_path, notice: 'The address has been updated successfully.' } format.json { render json: { result: true, address: @address } } else format.html { render 'edit' } format.json { render json: { result: false, errors: @address.errors. } } end end end |