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/rnhthe routes file
Rnh::Application.routes.draw do
resources :offers do
resource :details
resources :photos
end
endthe 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
endthe 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