NoMethodError in Books#index


I have completed all the code but when I run the project, I get an error like this…

This is the HTML file (app/views/books/index.html.erb) that generates the error…

<% @books.each do |book| %>
  <div class="book">
    <div class="row">
      <div class="col-md-1">
        <p class="rank-this-week"> <%= book.rank_this_week %> </p>
      <div class="col-md-9">
        <p class="title"> <%= book.title %> </p>
        <p class="author">by  <%= %></p>
        <p class="publisher">(<%= book.publisher %>)</p>
        <p class="description"> <%= book.description %> </p>
        <%= link_to 'See all Editorial Reviews', book %>
      <div class="col-md-2">
        <p class="weeks-on-list"> <%= book.weeks_on_list %> weeks on list</p>
<% end %>

This is my books_controller.rb

class BooksController < ApplicationController
  def index 
    @books = Book.all
  def show
  	@book = Book.find(params[:id])
  	@reviews =

And this is my routes.rb file

Rails.application.routes.draw do
  resource :books
  root 'books#index'


Hi @terawhiz79906,

Try linking to the book with book_url(book) instead:

<%= link_to 'See all Editorial Reviews', book_url(book) %>


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.