1 Replies - 2872 Views - Last Post: 25 November 2010 - 10:09 AM Rate Topic: -----

#1 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

undefined method `_index_path'

Posted 24 November 2010 - 03:01 PM

I keep getting the error "undefined method `knodes_index_path'" when I attempt to create a new post.

NoMethodError in Knodes#new

Showing ../knode/app/views/knodes/_form.html.erb where line #1 raised:
Extracted source (around line #1):
<%= form_for (@knodes) do |f| %>
   <% if @knodes.errors.any? %>
     <div id="error_explanation">
       <h2><%= pluralize(@knodes.errors.count, "error") %> prohibited this knode from being saved:</h2>



I'm using rails3. Here is the output for my routes, as i'm thinking it's a routing issue:

knodes GET    /knodes(.:format)          {:controller=>"knodes", :action=>"index"}
         knodes POST   /knodes(.:format)          {:controller=>"knodes", :action=>"create"}
      new_knode GET    /knodes/new(.:format)      {:controller=>"knodes", :action=>"new"}
     edit_knode GET    /knodes/:id/edit(.:format) {:controller=>"knodes", :action=>"edit"}
          knode GET    /knodes/:id(.:format)      {:controller=>"knodes", :action=>"show"}
          knode PUT    /knodes/:id(.:format)      {:controller=>"knodes", :action=>"update"}
          knode DELETE /knodes/:id(.:format)      {:controller=>"knodes", :action=>"destroy"}



I should note that if i create a new item for this in the Mysql database, I can view it in index, i can even edit it, but new just doesn't seem to work.

Here is the controller:


class KnodesController < ApplicationController
    before_filter :authenticate, :only => [:create, :destroy]
    before_filter :authorized_user, :only => :destroy
	
	 # GET /knodes
     # GET /knodes.xml
   def index
     @knodes = Knodes.all
   end

   # GET /knodes/1
   # GET /knodes/1.xml
   def show
     @knodes = Knodes.find(params[:id])
   end

   # GET /knodes/new
   # GET /knodes/new.xml
   def new
     @knodes = Knodes.new
   end

   # GET /knodes/1/edit
   def edit
     @knodes = Knodes.find(params[:id])
   end

   # POST /knodes
   # POST /posts.xml
   def create
     @knodes = current_user.knodes.build(params[:knodes])
     if @knodes.save
       redirect_to @user
     else
       render 'edit'
     end
   end

     # PUT /knodes/1
   # PUT /knodes/1.xml
   def update
     @knodes = Knodes.find(params[:id])

     if @knodes.update_attributes(params[:knodes])
       redirect_to @knodes
     else
       render 'edit'
     end
   end

   # DELETE /knodes/1
   # DELETE /knodes1.xml
   def destroy
     @knodes = Knodes.find(params[:id])
     @knodes.destroy

     respond_to do |format|
       format.html { redirect_to(knodes_url) }
       format.xml  { head :ok }
     end
   end

   private

   def authorized_user
     @knodes = Knodes.find(params[:id])
     redirect_to root_path unless current_user?(@knodes.user)
   end
 end



My other thoughts on this are, I was stupid for naming my class and methods similar names

This post has been edited by nimajneb: 24 November 2010 - 03:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: undefined method `_index_path'

#2 nimajneb  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 11
  • View blog
  • Posts: 116
  • Joined: 04-August 10

Re: undefined method `_index_path'

Posted 25 November 2010 - 10:09 AM

aaaand fixed it!

<% form_for @knodes, :url => { :action => :new } do |f| %>



added a little :url action! man that's been bugging me for days, so simple!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1