2016-11-22 2 views
0

Я изучаю Ruby on Rails в первый раз и пытаюсь настроить свой ноутбук, чтобы продолжить работу, когда я был на своем рабочем столе с моим проектом. Вчера у меня были некоторые проблемы с моим ноутбуком, работающим с Ruby через rvm и рабочим столом через rbenv, поэтому я исправил это. Теперь, однако, я получаю следующую ошибку на своем ноутбуке, но все отлично работает на моем ноутбуке.UrlGenerationError Нет совпадений маршрутов на одном компьютере, но не на другом

ActionController::UrlGenerationError in Categories#index 

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

     <table> 
     <tr> 
      <th class="table-header"><%= link_to 'housing', category_path(@housing) %></th> 
     </tr> 
     <tr> 
      <td> 

Я считаю, что это должно сработать. Если я правильно понимаю код, я связываюсь с моей категорией жилья через путь категории, передавая параметр @housing.

Как я уже говорил, это работает на моем рабочем столе.

Код следует заблаговременно за любую помощь.

выхода из моих рек маршрутов команды с маршрутом я пытаюсь использовать ...

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

index.html.erb

<div class="container"> 
    <div class="leftbar"> 
    <a href="#"><h1>rubyslist</h1></a> 
    <ul> 
     <a href="#"><%= link_to 'post a classifieds', new_listing_path %></a> 
     <li>my account</li> 
    </ul> 
     <p>search shiplist</p> 
     <%= form_tag search_listings_path, :method => 'get' do %> 
     <p> 
     <%= text_field_tag :search, params[:search] %> 
     <%= submit_tag "Search", :name => nil %> 
     </p> 
     <% end %> 
    </div> 
    <div class="center-column" > 
    <div class="center-one"> 
     <table> 
     <tr> 
      <th class="table-header"><%= link_to 'housing', category_path(@housing) %></th> 
     </tr> 
     <tr> 
      <td> 
      <% @housing.subcategories.each do |subcategory| %> 
      <ul class="left-list"> 
       <li><%= link_to subcategory.name, category_subcategory_path(@housing, subcategory) %></li> 
      </ul> 
      <% end %> 
      </td> 
     </tr> 
     </table> 
     <table> 
     <tr> 
      <th class="table-header"><%= link_to 'roommates', category_path(@roommates) %></th> 
     </tr> 
     <tr> 
      <td> 
      <% @roommates.subcategories.each do |subcategory| %> 
      <ul> 
       <li><%= link_to subcategory.name, category_subcategory_path(@roommates, subcategory) %></li> 
      </ul> 
      <% end %> 
      </td> 
     </tr> 
     </table> 
     <table> 
     <tr> 
      <th class="table-header"><%= link_to 'for sale', category_path(@forsale) %></th> 
     </tr> 
     <tr> 
      <td> 
      <% @forsale.subcategories.each do |subcategory| %> 
      <ul class="left-list"> 
       <li><%= link_to subcategory.name, category_subcategory_path(@forsale, subcategory) %></li> 
      </ul> 
      <% end %> 
      </td> 
     </tr> 
     </table> 
    </div> 
    </div> 
    <div class="rightbar"> 
    <!-- Links to the pages via routes match --> 
    <ul class="rightbar-top"> 
     <!-- /help --> 
     <li><%= link_to 'help and faq', help_path%></li> 
     <li><%= link_to 'avoid scams and fraud', scams_path%></li> 
     <li><%= link_to 'personal safety tips', safety_path%></li> 
     <li class="rightbar-top"><%= link_to 'terms of use', terms_path%></li> 
     <li><%= link_to 'privacy policy', privacy_path%></li> 
     <li><%= link_to 'about shiplist', about_path%></li> 
     <li><%= link_to 'contact us', contact_path%></li> 
    </ul> 
    </div> 
</div> 

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 

ответ

0

Выполнение команды

rake db:seed 

Исправлена ​​проблема.

Смежные вопросы