Rails 3 routing based on context -


I am trying to implement a "reference" system as used by geethbahb, for example, A user can be made a post with a user or a company, depending on whether the user is in the context of "user" or is referred to in any reference, which refers to any one of the companies.

As part of this, I want to be able to do routing based on the user's current context. For example, if the user is in their respective context, then the / dashboard should go in the path to the user / show , but if they are in the company context with ID35 , Then the / dashboard should go to companies / 35 / dashboard .

I can route / dashboard for a particular controller such as context # dashboard then redirect_to But it does not look right at all (probably because we are taking the argument that the rail route module

What would be the proper way to solve this problem?

-Text "itemprop =" text ">

Finally I found a solution to my problem which I liked. Rashni will use the URL.

First, the session-archived context object assumes that the user is in the "user" context or "company" reference or not. If the user " Company "in context, then they are working as the company ID that is also in the object. We can get the reference through the name of the code get_context and we are currently logged in -In user to current_user

config / routes.rb :

Pre> MyApplication :: Application.routes.draw "Dashboard" = & gt; get receive. "Redirect" ,: user = & gt; "/ User / show",: company = & gt; "/ Companies /: id / dashboard" end

Now, app / controller / redirect_controller.rb :

  class redirection Controller & LT; Reference to get_context case: user redirect_to user_url.gsub (": id", current_user.id.to_s) ApplicationController def method_missing (method, * args) user_url = params [user] company_url = params [: company] reference = get_context. When: Company_url.gsub (": id", context.id.to_s) End of End  

Redirecting is easy to maintain in the original URL, where they are related ( routes.rb file!) And that data has been passed in DRY controller. I can also pass in the current reference object ID in the passage.


Comments