Class: API::V1::GroupsController
- Inherits:
-
APIController
- Object
- ActionController::Base
- Faalis::ApplicationController
- Faalis::APIController
- APIController
- API::V1::GroupsController
- Defined in:
- app/controllers/faalis/api/v1/groups_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#index ⇒ Object
GET /api/v1/groups.
- #show ⇒ Object
- #update ⇒ Object
Methods inherited from Faalis::APIController
Methods inherited from Faalis::ApplicationController
Instance Method Details
#create ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 15 def create :create, Faalis::Group = []; (params[:permissions] || []).each do |perm_string| perm, model = perm_string.split "|" = Permission.(model, perm) << end @group = Group.new({ name: params[:name], permissions: , }) if @group.save respond_with(@group) else respond_to do |format| format.json { render :json => {:fields => @group.errors}, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
67 68 69 70 71 72 |
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 67 def destroy ids = params[:id].split(",") @groups = Group.where(:id => ids) :destory, @groups @groups.destroy_all end |
#index ⇒ Object
GET /api/v1/groups
9 10 11 12 13 |
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 9 def index @groups = Group.includes(:permissions).to_a :read, Faalis::Group respond_with(@groups) end |
#show ⇒ Object
39 40 41 42 43 |
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 39 def show @group = Group.find(params[:id]) :read, @group respond_with(@group) end |
#update ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/faalis/api/v1/groups_controller.rb', line 45 def update @group = Group.find(params[:id]) :update, @group = []; (params[:permissions] || []).each do |perm_string| perm, model = perm_string.split "|" = Permission.(model, perm) << end if @group.update(:name => params[:name], :permissions => ) respond_with(@group) else respond_to do |format| format.json { render :json => {:fields => @group.errors}, :status => :unprocessable_entity } end end end |