ruby - Rails Take all actions in the controllers in area -
in rails application add "api" area controllers
in route.rb file add area
namespace :api #get "dashboard/sales_rate" end
the controllers class:
class api::dashboardcontroller < api::applicationcontroller before_filter :authenticate_user! def user_service render :json => {"user_id" => current_user.id} end
the path is: app/controllers/api/dashboard_controller
my question if can route take action
for example /api/dashboard/user_service , not add each route row on route.rb page
/api/{controller_under_api_namespace}/{action}
you can meta programming sprinkle!
api.constants.each |c| c.action_methods.each |action| [c.controller_name, action].join('/') end end
this method limits get
request. can overcome restful routing.
api.constants.each |c| resources c.controller_name.to_sym end
hope, helps. :)
Comments
Post a Comment