Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What I would do is the following.</p> <p>First, create a scope or named_scope in your Project model for finding projects by type. You'll then be able to use this scope to query your projects depending on type.</p> <pre><code># Rails 3 class Project scope :by_type, lambda{ |type| where(type: type.to_i) unless type.nil? } end #Rails 2 class Project named_scope :by_type, lambda do |type| { :conditions =&gt; { :type =&gt; type.to_i } } unless type.nil? end end </code></pre> <p>Next, create a before filter in your controller to load the projects of that type. The before filter should be applied to all pages where you want the buttons to be present:</p> <pre><code>class ProjectsController before_filter :load_projects, :only =&gt; [:index, :action1, :action2] protected def load_projects @projects = Project.by_type(params[:type]) end end </code></pre> <p>Finally, create a partial for the buttons that you can include in the views that have the option of displaying different project types:</p> <pre><code># _project_options.html.erb &lt;%= link_to "Button 1", :controller =&gt; params[:controller], :action =&gt; params[:action], :type =&gt; '1' %&gt; &lt;%= link_to "Button 2", :controller =&gt; params[:controller], :action =&gt; params[:action], :type =&gt; '2' %&gt; &lt;%= link_to "Button 3", :controller =&gt; params[:controller], :action =&gt; params[:action], :type =&gt; '' %&gt; </code></pre> <p>You can then include this partial in each of your related views. And you'll be able to display the projects by doing something like this (if you have an _projects.html.erb partial defined):</p> <pre><code>render @projects </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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