Q:

Trying to filter results by a string attribute in rails

I am relatively new to Rails, I am trying to create a cookbook app/site from scratch, I'm not following any tutorials or anything like that. Anyway... I am still in the early stages of the site but I am now to the part where I am wanting to display a index list of all the different kinds of recipes. But I want to filter the list, for example: 
If I click on the 'vegetables' button on the navigation bar I would like to be take to an index page that only displays the different vegetable recipes.
I've gone ahead and added a string attribute to Recipes, called "category" thus I will be able to differentiate between Meat, Seafood, Poultry, Appetizers and Vegetable recipes. My goal is to only need the one controller 'recipes' and in the index action be able to conditionally filter on a param. Thus filtering the list by 'category' of food. But I am unsure how to go about doing so.
Here is my RecipesController:
class RecipesController < ApplicationController
  def index
    @recipes = Recipe.all
  end

  def show
     @recipe = Recipe.find(params[:id])
  end

  def new
  end

  def edit
  end

end

Here is my Routes file:
Rails.application.routes.draw do
  resources :recipes
  get 'vegetables' => 'recipes#vegetables'
  get 'poultry' => 'recipes#poultry'
  get 'meat' => 'recipes#meat'
  get 'seafood' => 'recipes#seafood'
  get 'appetizers' => 'recipes#appetizers'

  devise_for :users

  get 'about' => 'welcome#about'

  root to: 'welcome#index'

end

Here is the application layout file that contains the navigation bar:
<!DOCTYPE html>
<html>
<head>
  <title>Mrs. P's Cookbook</title>
  <link href='https://fonts.googleapis.com/css?family=Mate+SC' rel='stylesheet' type='text/css'>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>
</head>
<body>
  <div class="top-banner">
   <h1 class="banner-logo"> <%= link_to "Mrs. P's Cookbook", root_path %></h1>
   <nav>
    <%= link_to "POULTRY", poultry_path, class: "nav-link" %> |
    <%= link_to "MEAT", meat_path, class: "nav-link" %> |
    <%= link_to "SEAFOOD", seafood_path, class: "nav-link" %> |
    <%= link_to "APPETIZERS", appetizers_path, class: "nav-link" %> |
    <%= link_to "VEGETABLES", vegetables_path, class: "nav-link" %> |
    <%= link_to "ABOUT", about_path, class: "nav-link" %>
  </nav>

        <% if current_user %>
          Hello <%= current_user.email %>! <%= link_to "Sign out", destroy_user_session_path, method: :delete %>
        <% else %>
          <%= link_to "Sign In", new_user_session_path %> or
          <%= link_to "Sign Up", new_user_registration_path %>
        <% end %>
  </div>
<div class="white-field">
  <%= yield %>
    </div>
</body>
</html>

Here is my Recipe.rb model file:
class Recipe < ActiveRecord::Base
  has_many :comments

end

Here is my Recipe table:
  create_table "recipes", force: :cascade do |t|
    t.string   "title"
    t.text     "body"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.string   "category"
  end

I've got the different category views, Vegetables, Meat, Poultry, Seafood and Appetizers all inside the Recipe view folder. All of the views are empty except for some text that just says "Vegetable recipes will be listed here.", "Meat recipes will be listed here.", "Seafood recipes will be listed here.", etc..
I know what I am asking might be a tall order, so any help you guys can provide I will be extremely grateful for. If you need anymore information please let me know.

A:

I came up with two possible solutions (among many! :) )
Solution 1
One solution could be using a query string. The routes file would be
Rails.application.routes.draw do
  resources :recipes

  devise_for :users

  get 'about' => 'welcome#about'

  root to: 'welcome#index'

end

Now create the links with the category as argument. In your view:
...
  <nav>
    ['poultry','meat','seafood','appetizers','vegetables'].each do |category|
      <%= link_to category.upcase, 
                  recipes_path(category: category), 
                  class: "nav-link" %> |
    end
    <%= link_to "ABOUT", about_path, class: "nav-link" %>
  </nav>
...

And in the controller you can capture the category, querying the model as already showed in the other answers. For example
class RecipesController < ApplicationController
  def index
    @recipes = params[:category].blank? : Recipe.all :
               Recipe.where(category: params[:category])
  end

  ...
end

But isn't that elegant if you want to customize the view of a single category.
Solution 2
Add the following route, (before the resources :recipes )
Rails.application.routes.draw do
  get 'recipes/:category' => 'recipes#category', as: :recipes_category
  resources :recipes
  ...
end

Note that with the as: :recipes_category you can reference to this path using the recipes_category_path helper
Now we need to add the category action to the RecipesController
class RecipesController < ApplicationController
  ...

  def category
    @recipes = Recipe.where(category: params[:category])
  end

  ...
end

And the the path in the link_to will change to
 ...
 <%= link_to category.upcase, 
             recipes_category_path(category: category), 
             class: "nav-link" %> |
 ...

IMHO that's cleaner if you want to customize your view without caring the presence of the param and the url looks prettier :).
Looking forward
As already suggested by @denys281, the category field smells like a separate entity, related with the recipes with a N:1 relation.
The two model will have the associations
class Recipe < ActiveRecord::Base
  belongs_to :category
end

class Category < ActiveRecord::Base
  has_many :recipes
end

In that way, for example, you can easily have all the categories by calling 
Category.all

or the recipes for a category with
@category = Category.find(2)
@recipes = @category.recipes

It really depends on what you want to achieve. I hope I gave you some ideas on the argument.
Regarding the other suggestion of using Slim, I disagree. It's just syntactic sugar, it's not standard and it will confuse you: the most of the code you will find around will have the standard syntax.
Get your hands dirty before using some other tools, it will give you a better idea of the mechanisms behind, a better understanding if the tool will solve your needs and how you can customize it.
I suggest you to read the official rails guide, the countless blogs and articles and try to read code written by others ( thanks Open Source! ). 

