Note that there are some explanatory texts on larger screens.

plurals
  1. PORails controller and routes configuration for website
    text
    copied!<p>I have an application in RAILS, it is composed of a set of API, a basic website, and an admin dashboard. For the API routing I have no problems, as they belong to a model and a controller and are compliant with the RAILS RESTful pattern (a controller for each model, and a method for each HTTP method). </p> <p>What I'm not comfortable with is writing routes and controllers for website. The main website is at / so the default route is <code>root :to =&gt; "home#index"</code>and I have Routes for the website pages which look like </p> <pre><code> get "home/index" get "map/index" get "api/index" get "cgu/index" get "legal/index" </code></pre> <p>Which I think it is not good, as I have a controller per view and I need to define a get for each views. Now for the dashboard I tried a different approach. It is at /dashboard, the default route is <code>match "dashboard" =&gt; "dashboard#index"</code> and here is few pages as an examples</p> <pre><code> get "dashboard/index" get "dashboard/users" get "dashboard/users_stats" get "dashboard/routes" get "dashboard/routes_stats" get "dashboard/charts" get "dashboard/financial" </code></pre> <p>So for the dashboard I have a massive dashboard_controller, which contains a <code>def method</code> for each dashboard pages. IE: </p> <pre><code>#dashboard/users def users @users = User.all respond_to do |format| format.html {render :layout =&gt; 'dashboard'} end end </code></pre> <p>the controller of the dashboard is at /controller but for views and assets I have put it in /folder/dashboard/ </p> <p>Here is 2 questions: </p> <ul> <li>What is the best way to build the home website and dashboard ? Should I have a controller per page or a global controller where I have a method per pages ? (Which I find very convenient, less code). </li> <li>How should I organize my routes to avoid to set a get "something/something" for each page ? Or it is normal with RAILS that I have a route defined for each of my page ? I'm fairly new. </li> </ul> <p>EDIT: To clarify, the dashboard is built around an existing application with API that follow RESTFul Rails pattern:</p> <pre><code> resources :users resources :routes </code></pre> <p>But the dashboard is not tied to any existing resources, it only do stats about those resources. </p>
 

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