This time i read scaffold tutorial very carefully and finally try to generate a form without using the scaffold(just used a controller and view ).what i have done till now ,is as follow.Using rails 3.0.7. "rails generate controller posts index" 1) post_controller.rb class PostsController < ApplicationController def index @post=Post.new end def create @post = Post.new(params[:post]) respond_to do |format| end end end 2)index.html.erb <h1>Posts#index</h1> <p>Find me in app/views/posts/index.html.erb</p> <%= link_to ''New Post'', new_post_path%> <%= form_for(@post) do |f| %> <div class="field"> <%= f.label :name %><br /> <%= f.text_field :name %> </div> <div class="field"> <%= f.label :title %><br /> <%= f.text_field :title %> </div> <div class="field"> <%= f.label :content %><br /> <%= f.text_area :content %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> i didnt create any model because i just want to create a simple form first.so when i brower to "localhost:3000/ posts/index", it says "uninitialized constant PostsController::Post Please somebody help to resolve it Thanks -- 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 Apr 30, 2011, at 11:40 AM, amrit pal pathak wrote:> This time i read scaffold tutorial very carefully and finally try to > generate a form without using the scaffold(just used a controller and > view ).what i have done till now ,is as follow.Using rails 3.0.7. > > "rails generate controller posts > index" > > 1) post_controller.rb > > class PostsController < ApplicationController > def index > @post=Post.new > end > def create > @post = Post.new(params[:post]) > respond_to do |format| > end > end > end > > 2)index.html.erb > > <h1>Posts#index</h1> > <p>Find me in app/views/posts/index.html.erb</p> > <%= link_to ''New Post'', new_post_path%> > <%= form_for(@post) do |f| %> > <div class="field"> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </div> > <div class="field"> > <%= f.label :title %><br /> > <%= f.text_field :title %> > </div> > <div class="field"> > <%= f.label :content %><br /> > <%= f.text_area :content %> > </div> > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > i didnt create any model because i just > want to create a simple form first.so when i brower to "localhost: > 3000/ > posts/index", it says > > "uninitialized constant PostsController::Post > > Please somebody help to resolve it > > Thanks > >You must have a model if you''re going to call Post.new. That''s where that ''new'' method happens. The model tells the controller what fields it should initialize, which tells the view that the default values are whatever they are, etc. It''s MVC, not VC! Walter> > > > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- 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 30 April 2011 16:40, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This time i read scaffold tutorial very carefully and finally try to > generate a form without using the scaffold(just used a controller and > view ).what i have done till now ,is as follow.Using rails 3.0.7. > > "rails generate controller posts > index" > > 1) post_controller.rb > > class PostsController < ApplicationController > def index > @post=Post.newWhy are you making a post in the index action? This action should just be showing posts.> end > def create > @post = Post.new(params[:post]) > respond_to do |format| > end > end > end > > 2)index.html.erb > > <h1>Posts#index</h1> > <p>Find me in app/views/posts/index.html.erb</p> > <%= link_to ''New Post'', new_post_path%> > <%= form_for(@post) do |f| %> > <div class="field"> > <%= f.label :name %><br /> > <%= f.text_field :name %> > </div> > <div class="field"> > <%= f.label :title %><br /> > <%= f.text_field :title %> > </div> > <div class="field"> > <%= f.label :content %><br /> > <%= f.text_area :content %> > </div> > <div class="actions"> > <%= f.submit %> > </div> > <% end %> > > i didnt create any model because i just > want to create a simple form first.so when i brower to "localhost:3000/ > posts/index", it says > > "uninitialized constant PostsController::PostYou have not told us which line is failing, but I guess it is the one that says @post=Post.new which says make a new Post object, but since you have not written the Post model how can it make a Post object? You cannot make a form for an object without defining the model first. form_for( @post ) makes a form for the object @post. 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.
On Apr 30, 12:08 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 30 April 2011 16:40, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > This time i read scaffold tutorial very carefully and finally try to > > generate a form without using the scaffold(just used a controller and > > view ).what i have done till now ,is as follow.Using rails 3.0.7. > > > "rails generate controller posts > > index" > > > 1) post_controller.rb > > > class PostsController < ApplicationController > > def index > > @post=Post.new > > Why are you making a post in the index action? This action should > just be showing posts.Yes Colin,this method was used for showing phosts.But this is not a ard and fast rule that it must be used for showing posts.I just doing experiment ,so used it for creating .> > > > > > > > > > > end > > def create > > @post = Post.new(params[:post]) > > respond_to do |format| > > end > > end > > end > > > 2)index.html.erb > > > <h1>Posts#index</h1> > > <p>Find me in app/views/posts/index.html.erb</p> > > <%= link_to ''New Post'', new_post_path%> > > <%= form_for(@post) do |f| %> > > <div class="field"> > > <%= f.label :name %><br /> > > <%= f.text_field :name %> > > </div> > > <div class="field"> > > <%= f.label :title %><br /> > > <%= f.text_field :title %> > > </div> > > <div class="field"> > > <%= f.label :content %><br /> > > <%= f.text_area :content %> > > </div> > > <div class="actions"> > > <%= f.submit %> > > </div> > > <% end %> > > > i didnt create any model because i just > > want to create a simple form first.so when i brower to "localhost:3000/ > > posts/index", it says > > > "uninitialized constant PostsController::Post > > You have not told us which line is failing, but I guess it is the one that says > @post=Post.new > which says make a new Post object, but since you have not written the > Post model how can it make a Post object? > > You cannot make a form for an object without defining the model first. > form_for( @post ) makes a form for the object @post.@Colin and Walter ok,model is must.Created a model as. "rails generate model post" and then did "rake db:create"(it created a database) and then "rake db:migrate"(it created a posts tables in database).but now when i browse to "locahost:3000/posts/index",it says Showing /home/amrit/final/app/views/posts/index.html.erb where line #4 raised: undefined method `posts_path'' for #<#<Class:0xb67f7784>:0xb67f5560> Thanks for support!! -- 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 1 May 2011 05:52, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ... > Showing /home/amrit/final/app/views/posts/index.html.erb where line #4 > raised: > undefined method `posts_path'' for #<#<Class:0xb67f7784>:0xb67f5560>Amrit I cannot believe that you are asking that question. Look back through your questions and you will see you have asked similar questions several times. Always the answer is to rake routes to what routes you have defined (and so whether posts_path is valid) and to re-read the Rails Guides on Routing if you do not know how to get that path defined. Can you explain how it is that you have to keep asking the question? Am I the only one thinking that this poster is winding us up? 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.
On May 1, 4:12 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 1 May 2011 05:52, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ... > > Showing /home/amrit/final/app/views/posts/index.html.erb where line #4 > > raised: > > undefined method `posts_path'' for #<#<Class:0xb67f7784>:0xb67f5560> > > Amrit I cannot believe that you are asking that question. Look back > through your questions and you will see you have asked similar > questions several times. Always the answer is to rake routes to what > routes you have defined (and so whether posts_path is valid) and to > re-read the Rails Guides on Routing if you do not know how to get that > path defined. > > Can you explain how it is that you have to keep asking the question? > > Am I the only one thinking that this poster is winding us up?Not at all.He is new to Rails So I think we should help him to resolve the issue. -- 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.
Michael Pavling
2011-May-01 10:01 UTC
Re: Re: "uninitialized constant PostsController::Post"
On 1 May 2011 09:12, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Amrit I cannot believe that you are asking that question. > > Am I the only one thinking that this poster is winding us up?Since post 1 I''ve thought you''re banging your head against a wall :-/ Stuff like "this is not a [h]ard and fast rule that it must be used for showing posts." is ridiculous... If he wants to "just doing experiment" and use the index action to create, then be surprised at problems, then he''s on a limb on his own. I''m all for helping people, but they''ve got to help themselves first [1]. No-one is here to be anyone else''s crutch 24/7. [1] or at least be able to help themselves with some prompting.... -- 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 May 1, 5:11 am, John shelfer <johnsshel...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On May 1, 4:12 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > > > > > On 1 May 2011 05:52, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > ... > > > Showing /home/amrit/final/app/views/posts/index.html.erb where line #4 > > > raised: > > > undefined method `posts_path'' for #<#<Class:0xb67f7784>:0xb67f5560> > > > Amrit I cannot believe that you are asking that question. Look back > > through your questions and you will see you have asked similar > > questions several times. Always the answer is to rake routes to what > > routes you have defined (and so whether posts_path is valid) and to > > re-read the Rails Guides on Routing if you do not know how to get that > > path defined. > > > Can you explain how it is that you have to keep asking the question? > > > Am I the only one thinking that this poster is winding us up? > > Not at all.He is new to Rails So I think we should help him > to > resolve the issue.Thank you for support sir. -- 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 1 May 2011 10:11, John shelfer <johnsshelfer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On May 1, 4:12 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:>> On 1 May 2011 05:52, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> ...>> Am I the only one thinking that this poster is winding us up? > Not at all.He is new to Rails So I think we should help him > to > resolve the issue.Ok John. Thanks for volunteering to help sort Amrit out. Over to you. Good luck 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.