Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As suggested in the question <a href="https://stackoverflow.com/questions/4207657/rails-routing-to-handle-multiple-domains-on-single-application">Rails routing to handle multiple domains on single application</a>, I guess you could use <a href="http://guides.rubyonrails.org/routing.html#advanced-constraints" rel="nofollow noreferrer">Rails Routing - Advanced Constraints</a> to build what you need.</p> <p>If you have a limited space of controllers (with unlimited views pointing to them), this should work. Just create a constraint for each controller that verifies if the current view matches them.</p> <p>Assuming you have a space of 2 controllers (PostController and CommentController), you could add the following to your routes.rb:</p> <pre><code>match "*path" =&gt; "post#show", :constraints =&gt; PostConstraint.new match "*path" =&gt; "comment#show", :constraints =&gt; CommentConstraint.new </code></pre> <p>Then, create lib/post_constraint.rb:</p> <pre><code>class PostConstraint def matches?(request) 'post' == Rails.cache.fetch("/view_controller_map/#{request.params[:view_name]}") { View.find_by_name(request.params[:view_name]).controller } end end </code></pre> <p>Finally, create lib/comment_constraint.rb:</p> <pre><code>class CommentConstraint def matches?(request) 'comment' == Rails.cache.fetch("/view_controller_map/#{request.params[:view_name]}") { View.find_by_name(request.params[:view_name]).controller } end end </code></pre> <p>You can do some improvements, like defining a super constraint class that fetches the cache, so you don't have to repeat code and don't risk fetching a wrong cache key name in one of the constraints.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload