I''m at a complete loss. I can get to new and edit and when I submit the new post or submit the edit, i''ll get: Routing Error No route matches "/knodes/new" or Routing Error No route matches "/knodes/1/edit" Here''s 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 And my routes sessions_new GET /sessions/new(.:format) {:controller=>"sessions", :action=>"new"} knodes_new GET /knodes/new(.:format) {:controller=>"knodes", :action=>"new"} users_new GET /users/new(.:format) {:controller=>"users", :action=>"new"} pages_home GET /pages/home(.:format) {:controller=>"pages", :action=>"home"} pages_about GET /pages/about(.:format) {:controller=>"pages", :action=>"about"} pages_contact GET /pages/contact(.:format) {:controller=>"pages", :action=>"contact"} pages_changelog GET /pages/changelog(.:format) {:controller=>"pages", :action=>"changelog"} contact /contact(.:format) {:controller=>"pages", :action=>"contact"} about /about(.:format) {:controller=>"pages", :action=>"about"} signup /signup(.:format) {:controller=>"users", :action=>"new"} signin /signin(.:format) {:controller=>"sessions", :action=>"new"} signout /signout(.:format) {:controller=>"sessions", :action=>"destroy"} changelog /changelog(.:format) {:controller=>"pages", :action=>"changelog"} 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"} users GET /users(.:format) {:controller=>"users", :action=>"index"} users POST /users(.:format) {:controller=>"users", :action=>"create"} new_user GET /users/new(.:format) {:controller=>"users", :action=>"new"} edit_user GET /users/:id/edit(.:format) {:controller=>"users", :action=>"edit"} user GET /users/:id(.:format) {:controller=>"users", :action=>"show"} user PUT /users/:id(.:format) {:controller=>"users", :action=>"update"} user DELETE /users/:id(.:format) {:controller=>"users", :action=>"destroy"} sessions GET /sessions(.:format) {:controller=>"sessions", :action=>"index"} sessions POST /sessions(.:format) {:controller=>"sessions", :action=>"create"} new_session GET /sessions/new(.:format) {:controller=>"sessions", :action=>"new"} session DELETE /sessions/:id(.:format) {:controller=>"sessions", :action=>"destroy"} root /(.:format) {:controller=>"pages", :action=>"home"} ======================================== Also this is my first post on the ruby-forum! I hate that it''s for a problem i''m having. I''ve been looking for a good ruby/rails forum for a while. HOWDY! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 November 2010 22:06, Ben Woodall <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I''m at a complete loss. I can get to new and edit and when I submit the > new post or submit the edit, i''ll get: > > Routing Error > No route matches "/knodes/new"Are you saying that you can get to new ok, so you are in the view new.html.erb, then when you click the save button you get the routing error above? that seems a bit odd as it should be going to create not new. Have you checked in log/development.log to see if there is any more info? It may be that it is going to the create and then failing at the next stage. Does it create the new record? If you are sure it is not going to create then post the view code please.> > or > > Routing Error > No route matches "/knodes/1/edit"Similarly this should be going to update not edit. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks for the response! To clarify: I can actually get to new.html.erb and :id/edit.html.erb. the problem is on submit i''ll get those errors. it does not create or edit the post when i submit either. I have manually made 2 posts in mysql for testing purposes. Here is the newest lines in my log/dev: Started POST "/knodes/2/edit" for 72.1.183.251 at Thu Nov 25 13:35:41 -0800 2010 ActionController::RoutingError (No route matches "/knodes/2/edit"): Rendered /home/bwoodall/.gem/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms) Started GET "/knodes" for 72.1.183.251 at Thu Nov 25 13:38:35 -0800 2010 Processing by KnodesController#index as HTML Knodes Load (0.2ms) SELECT `knodes`.* FROM `knodes` ORDER BY knodes.created_at DESC Rendered layouts/_stylesheets.html.erb (2.4ms) User Load (0.2ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` 1) LIMIT 1 Rendered layouts/_header.html.erb (41.5ms) Rendered layouts/_footer.html.erb (1.9ms) Rendered knodes/index.html.erb within layouts/application (73.0ms) Completed 200 OK in 98ms (Views: 78.5ms | ActiveRecord: 0.4ms) Started GET "/knodes/new" for 72.1.183.251 at Thu Nov 25 13:38:37 -0800 2010 Processing by KnodesController#new as HTML User Load (0.1ms) SELECT `users`.* FROM `users` WHERE (`users`.`id` 1) LIMIT 1 DEPRECATION WARNING: <% %> style block helpers are deprecated. Please use <%= %>. (called from _app_views_knodes__new_form_html_erb__707979935__617958448_1646016 at /home/bwoodall/rails/knode/app/views/knodes/_new_form.html.erb:1) Rendered knodes/_new_form.html.erb (12.7ms) Rendered layouts/_stylesheets.html.erb (1.9ms) Rendered layouts/_header.html.erb (4.8ms) Rendered layouts/_footer.html.erb (1.8ms) Rendered knodes/new.html.erb within layouts/application (29.6ms) Completed 200 OK in 77ms (Views: 33.9ms | ActiveRecord: 0.1ms) Started POST "/knodes/new" for 72.1.183.251 at Thu Nov 25 13:38:46 -0800 2010 ActionController::RoutingError (No route matches "/knodes/new"): Rendered /home/bwoodall/.gem/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms) Started POST "/knodes/new" for 72.1.183.251 at Thu Nov 25 13:43:03 -0800 2010 ActionController::RoutingError (No route matches "/knodes/new"): Rendered /home/bwoodall/.gem/ruby/1.8/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.3ms) ========================================= knodes/_form.html.erb ====================<% form_for @knodes, :url => { :action => :edit } do |f| %> <% if @knodes.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@knodes.errors.count, "error") %> prohibited this knode from being saved:</h2> <ul> <% @knodes.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :title %><br /> <%= f.text_field :title %> </div> <div class="field"> <%= f.label :info %><br /> <%= h f.text_area :info, :class => "mceEditor" %> </div> <div class="field"> <%= f.label :media %><br /> <%= h f.text_area :media, :class => "mceEditor" %> </div> <div class="field"> <%= f.label :links %><br /> <%= h f.text_area :links, :class => "mceEditor" %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> ==========================edit.html.erb ==========================<h1>Editing Knode</h1> <%= render ''form'' %> <%= link_to ''Show'', @knodes %> | <%= link_to ''Back'', knodes_path %> ========================== -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It''s because of this line in the _form.html.erb...isn''t it... <% form_for @knodes, :url => { :action => :edit } do |f| %> the { :action => :edit } is keeping it on edit and not pushing it to update i put that in there for edit and new because without it for new.html.erb, i keep getting: ============================== NoMethodError in Knodes#new Showing .../app/views/knodes/_new_form.html.erb where line #1 raised: undefined method `knodes_index_path'' for #<#<Class:0xb65df780>:0xb65d71d4> Extracted source (around line #1): 1: <% form_for @knodes do |f| %> 2: <% if @knodes.errors.any? %> 3: <div id="error_explanation"> 4: <h2><%= pluralize(@knodes.errors.count, "error") %> prohibited this knode from being saved:</h2> ================================ So I guess this is a new problem all together. Taking the line: { :action => :edit } out of the _form.html.erb for edit makes it work btw. I guess my problem is with the NoMethodError in Knodes#new -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 26, 1:53 pm, Ben Woodall <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> ====================> <% form_for @knodes, :url => { :action => :edit } do |f| %>This is incorrect - your form should be submitting to the update or create action depending on whether the object is saved or not. If you just do <% form_for @knodes do |f| %> rails will handle this for you Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 November 2010 14:22, Ben Woodall <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> [...] > ==============================> NoMethodError in Knodes#new > > Showing .../app/views/knodes/_new_form.html.erb where line #1 raised: > > undefined method `knodes_index_path'' for > #<#<Class:0xb65df780>:0xb65d71d4> > > Extracted source (around line #1): > > 1: <% form_for @knodes do |f| %> > 2: <% if @knodes.errors.any? %> > 3: <div id="error_explanation"> > 4: <h2><%= pluralize(@knodes.errors.count, "error") %> prohibited > this knode from being saved:</h2> > ================================> > So I guess this is a new problem all together. Taking the line: > > { :action => :edit } > > out of the _form.html.erb for edit makes it work btw. I guess my > problem is with the NoMethodError in Knodes#newI am a bit confused about you naming for Knodes. In an earlier post you have def new @knodes = Knodes.new end which suggests that your model is class Knodes, and you seem to be using knodes for both the singular and plural. Rails can get confused if you do not follow the conventions, though it is possible to work around this. I would have expected, though, to see model Knode in model/knode.rb, and controller KnodesController in controllers/knodes_controller.rb. Whether this is part of your problem I do not know. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #964102:> On Nov 26, 1:53pm, Ben Woodall <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> ====================>> <% form_for @knodes, :url => { :action => :edit } do |f| %> > > This is incorrect - your form should be submitting to the update or > create action depending on whether the object is saved or not. > If you just do <% form_for @knodes do |f| %> rails will handle this > for you > > FredYeah, that''s the woeful conclusion I came to. As posted right before you did, without that line in _new_form.html.erb for a new post, I keep getting: ============================== NoMethodError in Knodes#new Showing .../app/views/knodes/_new_form.html.erb where line #1 raised: undefined method `knodes_index_path'' for #<#<Class:0xb65df780>:0xb65d71d4> Extracted source (around line #1): 1: <% form_for @knodes do |f| %> 2: <% if @knodes.errors.any? %> 3: <div id="error_explanation"> 4: <h2><%= pluralize(@knodes.errors.count, "error") %> prohibited this knode from being saved:</h2> ================================ So this is a new problem than the one I first submitted. Board etiquette: should I keep this post going for this new problem, or submit a new one? I really appreciate the help i''ve gotten so far btw. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law wrote in post #964106:> On 26 November 2010 14:22, Ben Woodall <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> >> out of the _form.html.erb for edit makes it work btw. I guess my >> problem is with the NoMethodError in Knodes#new > > I am a bit confused about you naming for Knodes. In an earlier post you > have > def new > @knodes = Knodes.new > end > which suggests that your model is class Knodes, and you seem to be > using knodes for both the singular and plural. Rails can get confused > if you do not follow the conventions, though it is possible to work > around this. I would have expected, though, to see model Knode in > model/knode.rb, and controller KnodesController in > controllers/knodes_controller.rb. Whether this is part of your > problem I do not know. > > ColinYeah...this is only my second rails project and I thinking that this is my problem. I screwed up on the naming conventions. Honestly, if you were to just tell me "this is your problem, fix it cuz there''s nothing else we can help you with" i''d pretty much understand. I think i''m going to have to start over on this and change the names around -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 26 November 2010 14:42, Ben Woodall <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Colin Law wrote in post #964106: >> On 26 November 2010 14:22, Ben Woodall <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >>> >>> out of the _form.html.erb for edit makes it work btw. I guess my >>> problem is with the NoMethodError in Knodes#new >> >> I am a bit confused about you naming for Knodes. In an earlier post you >> have >> def new >> @knodes = Knodes.new >> end >> which suggests that your model is class Knodes, and you seem to be >> using knodes for both the singular and plural. Rails can get confused >> if you do not follow the conventions, though it is possible to work >> around this. I would have expected, though, to see model Knode in >> model/knode.rb, and controller KnodesController in >> controllers/knodes_controller.rb. Whether this is part of your >> problem I do not know. >> >> Colin > > Yeah...this is only my second rails project and I thinking that this is > my problem. I screwed up on the naming conventions. Honestly, if you > were to just tell me "this is your problem, fix it cuz there''s nothing > else we can help you with" i''d pretty much understand. I think i''m > going to have to start over on this and change the names aroundI not going to guarantee this is the problem (in fact I suspect it may not be), but if it isn''t you will probably run into some problem with the names at some point if you don''t fix it now. The less code there is the easier to change. In addition to the model name I would suggest also making the variable names consistent. So for example it would be better if it were @knode = Knode.new and @knodes = Knode.all Apart from anything else, when you are writing code you will always know that @knode is a single item and @knodes is a set. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.