Rails 4.1: Creating routes by calling method in controller -


I want to make a method, when a call is called from a controller, a nested resource path will be given to a given name For example, for a specific controller, this will add ...

  class API :: V1 :: FU controller & lt; ApplicationController must be equal to_users_route end   

...

  name space: make API name: v1 resource: foo resource: user, Controller: 'API_Security' and End End   

... which will allow them to browse on / api / v1 / foo /: foo_id / users and send Request for ApiSecurityController Or can it go to Api :: V1 :: ApiSecurityController ? It does not matter clearly because they are all in the same place of place. I want to do it this way because I want to avoid dozens of lines:

  resources: foo resources: Users, administrators: 'api_security' end resources: times do resources: user, controller: 'api_security' end   

It is easy to use a method for setup and maintenance.

Until the request is received, I am fine for the controller, but it is an automatic creation of the routes that I am a little uncertain what is the best way to deal with this? The closest I am discussing a lot about the engines but it does not look right because this is not a different kind of functionality, which I want to add to my app, it's just a dynamic route that connects to the existing resources.

The advice is appreciated!

I finished building the blog post @ juanpasta, and sewing it according to my needs. Calling a method from the controllers has become a bad way to handle it. I wrote about the whole thing in my blog, but TL; DR:

  # First draft, "just make-at-work" code # app / controller / concerns / user_account RB Module User Authorization ActiveSupport Expand :: Anxiety module ClassMethods def register_new_resource (controller_name) AppName :: Application.routes.draw "#adding # controller_name}" Namespace: Make API Name Location: v1 Control resources resources_name.to_sym resources Users: Controller: 'User_security', Ultimate :: given_id end end end end end end user approval in # application_controller.rb. RB ['Resource 1', 'Resource2', 'Resource3'] Each {| Resources | ApplicationController.register_new_resource (resource)} # app / controller / API / v1 / user_security_controller.rb class API :: V1 :: UserController & lt; ApplicationController before_action: authenticate_user! Before_action: target_id def index end DEF show end personal attr_reader: root_resource def target_id # to get around params [: mystery_resource_id_name] `@target_id || = get_target_id end def get_target_id @root_resource = request.fullpath.split ('/') [3] .singularize params ["# {root_resource} _id" .to_sym] end def target_model @target_model || = Root_resource.capitalize.constantize end def given_id params [: given_id] end and    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -