[Rails] Re: undefined method?
I got it to work by creating a comments_controller.rb file and using
the same action definitions as the section3_controller
I'm not sure why i had to make a new controller though.
But, thanks for the help
On Oct 14, 7:09 pm, aperture science <mekkagoj...@gmail.com> wrote:
> Internet::Application.routes.draw do |map|
> get "internets/index"
> get "section4/index"
> get "section3/index"
> get "section2/index"
> get "section1/index"
> get "science/index"
> resources :users
> resources :comments
> map.connect '/blog/new', :controller => 'section3', :action => 'new'
> get 'login(.:format)' => 'user_session#new', :as => :login
> post 'login(.:format)' => 'user_session#create', :as => :login
> delete 'logout(.:format)' => 'user_session#destroy', :as => :logout
> get "home/index"
> root :to => "home#index"
> map.logout 'logout', :controller => 'user_session', :action =>
> 'destroy'
> map.logout 'logout', :controller => 'user_session', :action =>
> 'destroy'
> map.edit 'edit', :controller => 'users', :action => 'edit'
> map.internets 'internets', :controller => 'internets', :action =>
> 'index'
> map.section4 'random', :controller => 'section4', :action => 'index'
> map.section3 'blog', :controller => 'section3', :action => 'index'
> map.section2 'artistry', :controller => 'section2', :action =>
> 'index'
> map.section1 'home', :controller => 'section1', :action => 'index'
> end
>
> Thats the entirety of it. The area that is giving me trouble is in
> the 'section3' controller
>
> I can post comments from the console, and they do then show up in the
> index.
>
> and when I use "form_for :comments" the log shows the data being
> posted, but there's no INSERT INTO being executed
>
> It seems like the form is not reading from the controller
>
> thanks for the help
>
> On Oct 14, 6:26 pm, Erol Fornoles <erol.forno...@gmail.com> wrote:
>
> > Can you post your route setup again?
>
> > On Fri, Oct 15, 2010 at 4:31 AM, aperture science <mekkagoj...@gmail.com>wrote:
>
> > > Thanks, that gets the comment form loading.
>
> > > I added:
>
> > > def create
> > > @comment = Comment.new(params[:comments])
>
> > > respond_to do |format|
> > > if @comment.save
> > > format.html { redirect_to('/', :notice => 'comment posted') }
> > > format.xml { render :xml => @comment, :status
> > > => :created, :location => @comment }
> > > else
> > > format.html { render :action => "new" }
> > > format.xml { render :xml => @comment.errors, :status
> > > => :unprocessable_entity }
> > > end
> > > end
> > > end
>
> > > to my controller1_controller.rb file, and now when I click the submit
> > > button, I get the following error
> > > "uninitialized constant CommentsController"
>
> > > Despite the redirect_to('/', ...) the page is redirecting to /comments
>
> > > On Oct 14, 6:26 am, Erol Fornoles <erol.forno...@gmail.com> wrote:
> > > > Hmmm wait, I just noticed something. Could you rename your Comments
> > > > model to Comment (from plural to singular). Don't forget to rename the
> > > > model file (comments.rb to comment.rb)
>
> > > > On 10/14/10 8:52 PM, aperture science wrote:
>
> > > > > I'm still getting the "undefined method `comments_index_path'" error
>
> > > > > The extracted source points at:
> > > > > <%= form_for(@comment) do |format| %>
>
> > > > > I cannot find where that method would be being called from
> > > > > even..."comments_index_path" only appears in the development.log
>
> > > > > On Oct 14, 3:08 am, Erol Fornoles <erol.forno...@gmail.com> wrote:
> > > > >> You were using a singular resource when you should have defined a
> > > plural
> > > > >> one. Also, you can specify the controller on your RESTful route
> > > instead
> > > > >> of having to create a separate map.connect or match:
>
> > > > >> resources :comments, :controller => 'controller1'
>
> > > > >> I recommend that you use consistent naming with your controllers and
> > > > >> routes though.
>
> > > > >> HTH
>
> > > > >> On 10/14/10 5:53 PM, aperture science wrote:
>
> > > > >>> I'm trying to learn rails as I go along, and having a bit of trouble.
> > > > >>> There is an undefined method cropping that I don't know why rails
> > > > >>> thinks should be there.
>
> > > > >>> Firstly, I'm using rails 3, ruby 1.9.2
>
> > > > >>> I have a controller with an index action This part works fine, but i
> > > > >>> am trying to add a comment form to the page that is rendered by that
> > > > >>> index action.
>
> > > > >>> Supposing my controller is named controller1,
>
> > > > >>> I began this process first with:
>
> > > > >>> rails g model comments name:string content:text
> > > > >>> rake rb:migrate
>
> > > > >>> Then I went on to define an action to create the comments:
>
> > > > >>> within contoller1_controller.rb I added
> > > > >>> =========
> > > > >>> def new
> > > > >>> @comment = Comments.new
>
> > > > >>> respond_to do |format|
> > > > >>> format.html
> > > > >>> format.xml { render :xml => @comment }
> > > > >>> end
> > > > >>> end
> > > > >>> ========
>
> > > > >>> views/controller1/new.haml contains
> > > > >>> ========
> > > > >>> = render 'form'
> > > > >>> ========
>
> > > > >>> and _form.html.erb contains
> > > > >>> ========
> > > > >>> <%= form_for(@comment) do |format| %>
>
> > > > >>> <div class='commentForm'>
> > > > >>> <%= format.label :name %><br />
> > > > >>> <%= format.text_field :name %><br />
>
> > > > >>> <%= format.label :content %><br />
> > > > >>> <%= format.text_area :content %><br />
> > > > >>> <div class='commentSend'>
> > > > >>> <%= format.submit %>
> > > > >>> </div>
> > > > >>> </div>
>
> > > > >>> <% end %>
> > > > >>> =======
>
> > > > >>> I then added into routes.db the following lines:
> > > > >>> resource :comments
> > > > >>> map.connect '/controller1/new', :controller =>
> > > > >>> 'controller1', :action => 'new'
>
> > > > >>> Now, navigating to /controller1/new gives me this error:
>
> > > > >>> undefined method `comments_index_path'
>
> > > > >>> What am I missing?
>
> > > > >>> If I change the form to "form_for(:Comments)", then
> > > '/controller1/new'
> > > > >>> renders, however, when I then add "@comments = Comments.all" into
> > > the
> > > > >>> index definition, and:
> > > > >>> - @comments.each do |comment|
> > > > >>> - comment.content
> > > > >>> into the index.haml file, no comments are actually displayed. So I
> > > > >>> assume the form is not actually sending anything to the database
>
> > > > >>> Any tips on what I'm doing wrong would be greatly appreciated,
>
> > > > >>> Thanks
>
> > > > >> --
> > > > >> Erol Fornoleshttp://
> > > github.com/Erolhttp://twitter.com/erolfornoleshttp://ph.linked...
>
> > > > --
> > > > Erol Fornoleshttp://
> > > github.com/Erolhttp://twitter.com/erolfornoleshttp://ph.linkedin.com/in/erolfornoles
>
> > > --
> > > 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@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > rubyonrails-talk+unsubscribe@googlegroups.com<rubyonrails-talk%2Bunsubscribe@googlegroups.com>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/rubyonrails-talk?hl=en.
>
> > --
> > Erol M. Fornoleshttp://github.com/Erolhttp://twitter.com/erolfornoleshttp://ph.linked...
--
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home