Note that there are some explanatory texts on larger screens.

plurals
  1. POAlias route's name
    primarykey
    data
    text
    <p>I need to have one path accessible through multiple names. In my <code>routes.rb</code> I did</p> <pre><code>get '/route' =&gt; 'controller#edit', :as =&gt; 'name_a' get '/route' =&gt; 'controller#edit', :as =&gt; 'name_b' </code></pre> <p>This works nicely but loads the routes table for nothing. From my understanding of the documentation, <code>:as</code> defines a helper method when called.</p> <p>So I went to my <code>ApplicationController</code> and added</p> <pre><code>alias_method :name_b, :name_a </code></pre> <p>and I removed the second line from <code>routes.rb</code></p> <p>but that fails with <code>Uncaught exception: undefined method name_a for class ApplicationController</code></p> <p>is there any proper way of having two names for a single path?</p> <p>=================EDIT==================== Elaboration:</p> <p>I use Devise gem to manage session, registration, locking, etc. of 2 kinds of users, let's call them <code>Admin</code> and <code>Guest</code>. The gem is very well put but it asks for definitive route names to behave properly.</p> <p>In my case, as far as devise is concerned, only the registration process is different so I'm trying to build a structure which looks as follow:</p> <pre><code>app controllers users admin registration_controller.rb guest registration_controller.rb session_controller.rb password_controller.rb registration_controller.rb </code></pre> <p>the <code>Admin</code> and <code>Guest</code> controllers inherit from the above registration_controller which inherit's from Devise.</p> <p>Now, to work properly, Devise needs for instance the names <code>guest_user_password</code> and <code>admin_user_password</code> to create or delete password retrievals. In my case, both are under the same path so I want both names to redirect to the same 'users/password' controller.</p> <p>More important, and that's why I really wanted the alaising. Is that my views should not care whether it is dealing with <code>Admin</code> and <code>Guest</code> routes when redirecting to password retrieval controller. Both are users so I want to use <code>user_password</code> for both.</p> <p>Hence my question. :)</p> <p>Also note that as I wrote it, things works. I'm just trying to get the 'most elegant way' of writing it.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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