Class: Admin::Api::MenuItemsController
- Inherits:
-
Admin::ApiController
- Object
- Admin::ApiController
- Admin::Api::MenuItemsController
- Defined in:
- app/controllers/admin/api/menu_items_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #index ⇒ Object
- #initial_data ⇒ Object
- #set_default ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 12 def create @menu = Odania::Menu.where(site_id: params[:site_id], id: params[:menu_id]).first bad_api_request('invalid_menu') if @menu.nil? @menu_item = Odania::MenuItem.new(content_params) @menu_item.target_data = odania_target_data_params @menu_item. = @menu.id if @menu_item.save if @menu..nil? and @menu_item.published @menu. = @menu_item.id @menu.save end flash[:notice] = t('created') render action: :show else render json: {errors: @menu_item.errors}, status: :bad_request end end |
#destroy ⇒ Object
43 44 45 46 47 48 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 43 def destroy @menu_item.destroy flash[:notice] = t('deleted') render json: {message: 'deleted'} end |
#index ⇒ Object
5 6 7 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 5 def index @menu_items = Odania::MenuItem.where(menu_id: params[:menu_id]).order('title ASC') end |
#initial_data ⇒ Object
50 51 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 50 def initial_data end |
#set_default ⇒ Object
53 54 55 56 57 58 59 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 53 def set_default @menu. = @menu_item.id @menu.save! @menu_items = Odania::MenuItem.where(menu_id: @menu.id).order('title ASC') render action: :index end |
#show ⇒ Object
9 10 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 9 def show end |
#update ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/admin/api/menu_items_controller.rb', line 33 def update @menu_item.target_data = odania_target_data_params if @menu_item.update(content_params) flash[:notice] = t('updated') render action: :show else render json: {errors: @menu_item.errors}, status: :bad_request end end |