Maverick
Maverick

Reputation: 2760

undefined method error in view

I am developing a rails application, and theres a method called ned inside pages controller. I want to display a form_for(@pages) but its giving me this error:

`NoMethodError in Pages#new

Showing C:/rorapp/app/views/pages/_form.html.erb where line #1 raised:

undefined method `pages_path' for #<#<Class:0x5a8d840>:0x5a8a558>
Extracted source (around line #1):

1: <%= form_for(@pages) do |f| %>
2:   
3: <% end %>
Trace of template inclusion: app/views/pages/new.html.erb

Rails.root: C:/rorapp

Application Trace | Framework Trace | Full Trace
app/views/pages/_form.html.erb:1:in `_app_views_pages__form_html_erb__975660997_47429844'
app/views/pages/new.html.erb:2:in `_app_views_pages_new_html_erb___256256638_47474016'
app/controllers/pages_controller.rb:11:in `new'`

Here is my controller method in pages controller:

def new
    @pages = Page.new
    
    respond_to do |format|
    format.html  # new.html.erb
    format.json  { render :json => @post }
    end
  end

Here is the partial form view _form.html.erb:

<%= form_for(@pages) do |f| %>
  
<% end %>

and here is how I am using it in the new.html.erb view: <%= render 'form' %> What could be the problem?

EDIT -1

here is my rake routes command output:

home_index  GET  /home/index(.:format)      {:controller=>"home", :action=>"index"}
home_search POST /home/search(.:format)     {:controller=>"home", :action=>"search"}
home__help  GET  /home/_help(.:format)      {:controller=>"home", :action=>"_help"}
home_create GET  /home/create(.:format)     {:controller=>"home", :action=>"create"}
pages_index GET  /pages/index(.:format)     {:controller=>"pages", :action=>"index"}
pages_new   GET  /pages/new(.:format)       {:controller=>"pages", :action=>"new"}
            POST /pages/new(.:format)       {:controller=>"pages", :action=>"new"}
pages_edit  POST /pages/edit(.:format)      {:controller=>"pages", :action=>"edit"}
            GET  /pages/edit(.:format)      {:controller=>"pages", :action=>"edit"}
root             /                          {:controller=>"home", :action=>"index"}
                 /:controller(/:action(/:id(.:format)))

Upvotes: 0

Views: 960

Answers (1)

Jasdeep Singh
Jasdeep Singh

Reputation: 3326

@mad_programmer - Please add resources :pages in your routes.rb file like others suggested.

Upvotes: 1

Related Questions