Topic: Rails - NameError and incorrect routing done by form_for method

I am creating an application and this is the error I am getting after running the application

NameError in Offers#index

Showing /home/fash/projs/rnh/app/views/offers/index.html.erb where line #19 raised:

undefined local variable or method `new_offers_path' for #<#<Class:0x95806c0>:0x9c51b5c>
Extracted source (around line #19):

16:   <% end %>
17: </table>
18: 
19: <p><%= link_to "New Offers", new_offers_path %></p>
Rails.root: /home/fash/projs/rnh

the routes file

Rnh::Application.routes.draw do
  resources :offers do
    resource :details
    resources :photos
  end 
end

the offers_controller file

class OffersController < ApplicationController
  def index
    @offers = Offers.all
  end

  def show
    @offers = Offers.find(params[:id])
  end

  def new
    @offers = Offers.new
  end

  def create
    @offers = Offers.new(params[:offers])
    if @offers.save
      redirect_to @offers, :notice => "Successfully created offers."
    else
      render :action => 'new'
    end
  end

  def edit
    @offers = Offers.find(params[:id])
  end

  def update
    @offers = Offers.find(params[:id])
    if @offers.update_attributes(params[:offers])
      redirect_to @offers, :notice  => "Successfully updated offers."
    else
      render :action => 'edit'
    end
  end

  def destroy
    @offers = Offers.find(params[:id])
    @offers.destroy
    redirect_to offers_url, :notice => "Successfully destroyed offers."
  end
end

the index.html.erb file:

<% title "Offers" %>

<table>
  <tr>
    <th>U</th>
    <th>Available</th>
  </tr>
  <% for offers in @offers %>
    <tr>
      <td><%= offers.u_id %></td>
      <td><%= offers.available %></td>
      <td><%= link_to "Show", offers %></td>
      <td><%= link_to "Edit", edit_offers_path(offers) %></td>
      <td><%= link_to "Destroy", offers, :confirm => 'Are you sure?', :method => :delete %></td>
    </tr>
  <% end %>
</table>

<p><%= link_to "New Offers", new_offers_path %></p>

I am new to rails and am not getting what can be the problem? is it the naming convention ? or something else? If anything else is needed please do post I need to sort the problem soon

Re: Rails - NameError and incorrect routing done by form_for method

Nothing wrong with your code as far as I can see.
Reboot your PC and try again. Maybe something is messing with your development environment and preventing your server from using your latest code. A reboot is a bit of overkill, normally just restarting your webserver should be enough but in this case I would suggest there is something more fundamentally wrong with your environment

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Rails - NameError and incorrect routing done by form_for method

the error was with pluralization of the model, so i renamed it as offer rather than offers