Routes/Link_to working on one computer but not the other.

**EDIT:** Running the command rake db:seed fixed the problem for me.

I'm learning Ruby on Rails for the first time, and have been trying to setup my laptop to continue where I was on my desktop with my project. I had some issues yesterday of my laptop running Ruby through rvm and desktop running through rbenv, so I fixed that. Now however, I am getting the following error on my laptop but everything works fine on my laptop.

ActionController::UrlGenerationError in Categories#index

No route matches {:action=>"show", :controller=>"categories", :id=>nil} missing required keys: [:id]

<%= link_to 'housing', category_path(@housing) %>

I believe it should work. If I understand the code right, I am linking to my housing category via the category path by passing in the @housing parameter and the @housing should have the id as per my categories_controller below.

Like I said, this works on my desktop! It links where I want it to, but here it doesn't.

Code as follows thanks in advance for any help.

output from my rake routes command with the route I am trying to use...

category GET /categories/:id(.:format) categories#show

index.html.erb

rubyslist

search shiplist

<%= form_tag search_listings_path, :method => 'get' do %>

<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>

<% end %>

<%= link_to 'housing', category_path(@housing) %>
<% @housing.subcategories.each do |subcategory| %>

  • <%= link_to subcategory.name, category_subcategory_path(@housing, subcategory) %>

<% end %>

<%= link_to 'roommates', category_path(@roommates) %>
<% @roommates.subcategories.each do |subcategory| %>

  • <%= link_to subcategory.name, category_subcategory_path(@roommates, subcategory) %>

<% end %>

<%= link_to 'for sale', category_path(@forsale) %>
<% @forsale.subcategories.each do |subcategory| %>

  • <%= link_to subcategory.name, category_subcategory_path(@forsale, subcategory) %>

<% end %>

  • <%= link_to 'help and faq', help_path%>
  • <%= link_to 'avoid scams and fraud', scams_path%>
  • <%= link_to 'personal safety tips', safety_path%>
  • <%= link_to 'terms of use', terms_path%>
  • <%= link_to 'privacy policy', privacy_path%>
  • <%= link_to 'about shiplist', about_path%>
  • <%= link_to 'contact us', contact_path%>

routes.rb

#Creates CRUD actions for categories
resources :categories do
#Append sub-categories to categories with CRUD
resources :subcategories
end

#Performs the search
resources :listings do
collection do
get 'search'
end
end

#Set homepage to index of categories
root 'categories#index'

#Matches the pages help action to a get request
#for the help page with page controller in help
#function of pages controller
match '/help', to: 'pages#help', via: :get
match '/scams', to: 'pages#scams', via: :get
match '/safety', to: 'pages#safety', via: :get
match '/about', to: 'pages#about', via: :get
match '/contact', to: 'pages#contact', via: :get
match '/privacy', to: 'pages#privacy', via: :get
match '/terms', to: 'pages#terms', via: :get
match '/subcategories/find_by_category', to: 'subcategories#find_by_category', via: :post
end

categories_controller.rb

class CategoriesController < ApplicationController #The index page of our categories controller def index @categories = Category.all @housing = @categories[0] @roommates = @categories[1] @forsale = @categories[2] end def show @listings = Listing.where(category_id: params[:id]) end end

1 thought on “Routes/Link_to working on one computer but not the other.”

Leave a Comment