I got a following error. NoMethodError in Book#new Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 raised: undefined method `model_name'' for NilClass:Class The content of _form.html.erb file are: <%= form_for(@post) do |f| %> <% if @post.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> <ul> <% @post.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <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 %> Any clue? 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.
I got a following error. NoMethodError in Book#new Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 raised: undefined method `model_name'' for NilClass:Class The content of _form.html.erb file are: <%= form_for(@post) do |f| %> <% if @post.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2> <ul> <% @post.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <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 %> Any clue? 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.
What does your controller look like? Do you define the @post variable? -- 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 25, 9:01 am, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> wrote:> What does your controller look like? Do you define the @post variable?Yes i defined it.it looks like class BookController < ApplicationController def index @book =Book.all render :index end end 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Actually it looks like you''re not defining it in the example you provided. Your controller is defining a variable called @book, but your view is trying to reference a variable called @post. Do you have a PostsController? -- 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 25, 9:37 am, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> wrote:> Actually it looks like you''re not defining it in the example you provided. > > Your controller is defining a variable called @book, but your view is trying > to reference a variable called @post. Do you have a PostsController?Yes it was mistake,but now i changed @post to @book.Still same error exits NoMethodError in Book#new Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 raised: undefined method `model_name'' for NilClass:Class 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 April 2011 16:50, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 25, 9:37 am, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> wrote: >> Actually it looks like you''re not defining it in the example you provided. >> >> Your controller is defining a variable called @book, but your view is trying >> to reference a variable called @post. Do you have a PostsController? > Yes it was mistake,but now i changed @post to @book.Still > same error exits > NoMethodError in Book#new > Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 > raised: > undefined method `model_name'' for NilClass:ClassIn that case @book is probably nil. Have a look at the Rails Guide on debugging and it will show you how to use ruby-debug to break into your code and inspect data and follow flow. Then you can debug these issues for yourself. Another useful technique is to open the rails console in your app by rails console then you can run code to see what happens. For example you could enter, in the console Book.all and it would show you the result of that. Note though that if you are using @book = Book.all as in an earlier post, that should give you an array of books not a single one, so formFor(@book) would not be valid. I don''t think that would not give the nil error you are seeing however. You probably want Book.first or a query to select a particular book. That assumes you have a book in the database of course. If you want to create a new one then perhaps @book = Book,new is what you want. 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 25, 11:59 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 25 April 2011 16:50, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Apr 25, 9:37 am, Tim Shaffer <timshaf...-BUHhN+a2lJ4@public.gmane.org> wrote: > >> Actually it looks like you''re not defining it in the example you provided. > > >> Your controller is defining a variable called @book, but your view is trying > >> to reference a variable called @post. Do you have a PostsController? > > Yes it was mistake,but now i changed @post to @book.Still > > same error exits > > NoMethodError in Book#new > > Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 > > raised: > > undefined method `model_name'' for NilClass:Class > > In that case @book is probably nil. > > Have a look at the Rails Guide on debugging and it will show you how > to use ruby-debug to break into your code and inspect data and follow > flow. Then you can debug these issues for yourself. > > Another useful technique is to open the rails console in your app by > rails console > then you can run code to see what happens. For example you could > enter, in the console > Book.all > and it would show you the result of that. > > Note though that if you are using > @book = Book.all > as in an earlier post, that should give you an array of books not a > single one, so formFor(@book) would not be valid. I don''t think that > would not give the nil error you are seeing however. You probably > want Book.first or a query to select a particular book. > That assumes you have a book in the database of course. If you want > to create a new one then perhaps > @book = Book,new > is what you want.Now i wont want arrary of books for display.I just want to create a empty form for book so in controller i removed "@book.Book.all" .Now controller only holds class BookController < ApplicationController def index @book =Book.new end end 1)Index.html.erb: <h1>Books are coming soon!</h1> <h1>Listing Books</h1> <table> <tr> <th>Title</th> <th>Summary</th> <th></th> <th></th> <th></th> </tr> <% @book.each do |book| %> <tr> <td><%= book.title %></td> <td><%= book.content %></td> </tr> <% end %> </table> <br /> <%= link_to ''New book'', new_book_path%> 2)new.html.erb: <h1>New post</h1> <%= render ''form'' %> 3)_form.html.erb <%= form_for(@book) do |f| %> <% if @book.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@book.errors.count, "error") %> prohibited this book from being saved:</h2> <ul> <% @book.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <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 %> Still Error says NoMethodError in Book#index Showing /home/amrit/boook/app/views/book/index.html.erb where line #14 raised: undefined method `each'' for #<Book id: nil, created_at: nil, updated_at: nil> Thanks 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 26 April 2011 08:56, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ... > class BookController < ApplicationController > def index > @book =Book.newThink about what this is doing. What is @book? It is a new Book object, not surprisingly.> end > end > > > 1)Index.html.erb: > > <h1>Books are coming soon!</h1> > <h1>Listing Books</h1> > <table> > <tr> > <th>Title</th> > <th>Summary</th> > <th></th> > <th></th> > <th></th> > </tr> > <% @book.each do |book| %>Above is the line the error is on, what is it supposed to be doing? Please explain what you think it means.> ... > NoMethodError in Book#index > > Showing /home/amrit/boook/app/views/book/index.html.erb where line #14 > raised: > > undefined method `each'' for #<Book id: nil, created_at: nil, > updated_at: nil>When you see an error it is not always easy for a beginner to work out what it means. Please try and work it out for yourself before asking here. What do you think it might mean? Also as I asked above, what do you think that line is supposed to do? Colin I just hope I am building up rewards for when it is time to meet my Maker. -- 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 26, 4:15 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 April 2011 08:56, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ... > > class BookController < ApplicationController > > def index > > @book =Book.new > > Think about what this is doing. What is @book? It is a new Book > object, not surprisingly. > > > > > > > > > > > end > > end > > > 1)Index.html.erb: > > > <h1>Books are coming soon!</h1> > > <h1>Listing Books</h1> > > <table> > > <tr> > > <th>Title</th> > > <th>Summary</th> > > <th></th> > > <th></th> > > <th></th> > > </tr> > > <% @book.each do |book| %> > > Above is the line the error is on, what is it supposed to be doing? > Please explain what you think it means.I think it retrieves the book details like title and contents from database.But here it no use so am removing this block. <% @book.each do |book| %> <tr> <td><%= book.title %></td> <td><%= book.content %></td> </tr> <% end %>> > NoMethodError in Book#index > > > Showing /home/amrit/boook/app/views/book/index.html.erb where line #14 > > raised: > > > undefined method `each'' for #<Book id: nil, created_at: nil, > > updated_at: nil> > > When you see an error it is not always easy for a beginner to work out > what it means. Please try and work it out for yourself before asking > here. What do you think it might mean? Also as I asked above, what > do you think that line is supposed to do?Amrit pal -- 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.
Afer removing that block(from index.html.erb) ,i can see localhost: 3000/book ,but when i click on "New book" link it gave follwoing error NoMethodError in Book#new Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 raised: undefined method `model_name'' for NilClass:Class 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 26 April 2011 09:23, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 26, 4:15 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 26 April 2011 08:56, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> > ... >> > class BookController < ApplicationController >> > def index >> > @book =Book.new >> >> Think about what this is doing. What is @book? It is a new Book >> object, not surprisingly. >> >> > <% @book.each do |book| %> >> >> Above is the line the error is on, what is it supposed to be doing? >> Please explain what you think it means. > > I think it retrieves the book details like title and > contents from database.How would @book.each retrieve contents from the db? ''each'' is a method of Array (or other collection) that iterates the collection passing each one to the block. Since @book is not a collection but is a single Book then each is not a valid method to call.> But here it no use so am removing this block.Very sensible, though why you are doing this in the index method I do not know, it looks as if it would be more appropriate in the ''new'' method. I presume you are just experimenting however, which is fine. 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 26, 4:30 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Afer removing that block(from index.html.erb) ,i can see localhost: > 3000/book ,but when i click on "New book" link it gave follwoing error > > NoMethodError in Book#new > > Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 > raised: > > undefined method `model_name'' for NilClass:ClassShould creation of model by "rails generate model book" will resolve this error?? -- 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 April 2011 09:41, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 26, 4:30 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> Afer removing that block(from index.html.erb) ,i can see localhost: >> 3000/book ,but when i click on "New book" link it gave follwoing error >> >> NoMethodError in Book#new >> >> Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 >> raised: >> >> undefined method `model_name'' for NilClass:Class > Should creation of model by "rails generate model book" > will resolve this error??You already have a Book model so no point generating it again. You have had this error before, please read the error carefully. It says that something is nil that should not be. Earlier I suggested using ruby-debug to break into your code to see what is going on. What do you see if you break in at this point in the code? 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 26 April 2011 09:15, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> I just hope I am building up rewards for when it is time to meet my Maker.You have the patience of a saint.... -- 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 26, 4:44 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 April 2011 09:41, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Apr 26, 4:30 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> Afer removing that block(from index.html.erb) ,i can see localhost: > >> 3000/book ,but when i click on "New book" link it gave follwoing error > > >> NoMethodError in Book#new > > >> Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 > >> raised: > > >> undefined method `model_name'' for NilClass:Class > > Should creation of model by "rails generate model book" > > will resolve this error?? > > You already have a Book model so no point generating it again.Yes you are right> > You have had this error before, please read the error carefully. It > says that something is nil that should not be.Nil means it says db has nothing to show or else??> Earlier I suggested using ruby-debug to break into your code to see > what is going on. What do you see if you break in at this point in > the code?I used the rails console it says amrit@ubuntu:~/boook$ rails console Loading development environment (Rails 3.0.7) irb(main):001:0> Book.all => [] Please let me clear,i am just expermenting.Please Guides me to just generate a empty form with two fields (name and content)after click on "New Book " link in the index.html.erb file(May be without it is connected to db). Thanks for continuos 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 Apr 26, 4:46 am, Michael Pavling <pavl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 26 April 2011 09:15, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > I just hope I am building up rewards for when it is time to meet my Maker. > > You have the patience of a saint....Thanks 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 26 April 2011 09:59, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 26, 4:44 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 26 April 2011 09:41, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> > On Apr 26, 4:30 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> > wrote: >> >> Afer removing that block(from index.html.erb) ,i can see localhost: >> >> 3000/book ,but when i click on "New book" link it gave follwoing error >> >> >> NoMethodError in Book#new >> >> >> Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 >> >> raised: >> >> >> undefined method `model_name'' for NilClass:Class >> > Should creation of model by "rails generate model book" >> > will resolve this error?? >> >> You already have a Book model so no point generating it again. > > Yes you are right >> >> You have had this error before, please read the error carefully. It >> says that something is nil that should not be. > Nil means it says db has nothing to show or else??Nothing to do with the database directly, it is saying a variable that you are using is nil. Look at where you setup the variable that is nil to find out why.>> Earlier I suggested using ruby-debug to break into your code to see >> what is going on. What do you see if you break in at this point in >> the code? > I used the rails console it says > > amrit@ubuntu:~/boook$ rails console > Loading development environment (Rails 3.0.7) > irb(main):001:0> Book.all > => []That is saying that there are no books in the database, but that is not necessarily anything to do with your problem. As I said earlier look at where you are setting up the variable that is nil. 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 26, 5:09 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 26 April 2011 09:59, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > On Apr 26, 4:44 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 26 April 2011 09:41, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > >> > On Apr 26, 4:30 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> > wrote: > >> >> Afer removing that block(from index.html.erb) ,i can see localhost: > >> >> 3000/book ,but when i click on "New book" link it gave follwoing error > > >> >> NoMethodError in Book#new > > >> >> Showing /home/amrit/boook/app/views/book/_form.html.erb where line #1 > >> >> raised: > > >> >> undefined method `model_name'' for NilClass:Class > >> > Should creation of model by "rails generate model book" > >> > will resolve this error?? > > >> You already have a Book model so no point generating it again. > > > Yes you are right > > >> You have had this error before, please read the error carefully. It > >> says that something is nil that should not be. > > Nil means it says db has nothing to show or else?? > > Nothing to do with the database directly, it is saying a variable that > you are using is nil. Look at where you setup the variable that is > nil to find out why. > > >> Earlier I suggested using ruby-debug to break into your code to see > >> what is going on. What do you see if you break in at this point in > >> the code? > > I used the rails console it says > > > amrit@ubuntu:~/boook$ rails console > > Loading development environment (Rails 3.0.7) > > irb(main):001:0> Book.all > > => [] > > That is saying that there are no books in the database, but that is > not necessarily anything to do with your problem. As I said earlier > look at where you are setting up the variable that is nil.is it saying @book variablei is nil? it is defined in controller as : class BookController < ApplicationController def index @book =Book.new end end One thing more,in new.html.erb,i have written "render ''form'' ",but there is no such file (view).The file there is _form.html.erb.Is it correct? Amrit pal -- 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 26, 10:21 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > is it saying @book variablei is nil? > it is defined in controller as : > > class BookController < ApplicationController > def index > @book =Book.new > end > endYour index action defines @book, but you''re testing the "new" action.> One thing more,in > new.html.erb,i have written "render ''form'' ",but there is no such file > (view).The file there is _form.html.erb.Is it correct?That''s ok - rails will work that bit out. Fred> > Amrit pal-- 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 26, 5:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 26, 10:21 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > is it saying @book variablei is nil? > > it is defined in controller as : > > > class BookController < ApplicationController > > def index > > @book =Book.new > > end > > end > > Your index action defines @book, but you''re testing the "new" action.Correspond to index action i have index file which hold following code and i can access this file successfully but when i click on "New book",it gives the error <h1>Books are coming soon!</h1> <h1>Listing Books</h1> <table> <tr> <th>Title</th> <th>Summary</th> <th></th> <th></th> <th></th> </tr> </table> <br /> <%= link_to ''New book'', new_book_path%>> > One thing more,in > > new.html.erb,i have written "render ''form'' ",but there is no such file > > (view).The file there is _form.html.erb.Is it correct? > > That''s ok - rails will work that bit out.Ok .but if i change the name from _form to form ,is will ok? 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
amritpal p. wrote in post #995086:> Stuff...You seem to be lacking some fundamental "organizational" knowledge as it pertains to a Rails application. What I found very instructive way back when was to scaffold a basic application and see what Rails created, and how it was organized. Then I fiddled with that scaffolded application, one change at a time. If you have an existing application, you can just add a scaffolded model, controller, and views via: rails g scaffold person first_name:string last_name:string (doesn''t have to be person, could be anything, just give it a model name and some attributes with types). Then look at the controller, model, and views that are created. Most enlightening. -- 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 Apr 2011, at 12:28, amrit pal pathak <amritpalpathak1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Apr 26, 5:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Apr 26, 10:21 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> >> >> >>> is it saying @book variablei is nil? >>> it is defined in controller as : >> >>> class BookController < ApplicationController >>> def index >>> @book =Book.new >>> end >>> end >> >> Your index action defines @book, but you''re testing the "new" action. > Correspond to index action i have index file which > hold following code and i can access this file successfully but when i > click on "New book",it gives the errorYes, we know that. What you don''t seem to grasp is that because the new page is being displayed the index method isn''t called (the new method, if it exists will be called) so @book isn''t set Fred> <h1>Books are coming soon!</h1> > > <h1>Listing Books</h1> > > <table> > <tr> > <th>Title</th> > <th>Summary</th> > <th></th> > <th></th> > <th></th> > </tr> > </table> > <br /> > <%= link_to ''New book'', new_book_path%> > > >>> One thing more,in >>> new.html.erb,i have written "render ''form'' ",but there is no such file >>> (view).The file there is _form.html.erb.Is it correct? >> >> That''s ok - rails will work that bit out. > > Ok .but if i change the name from _form to form ,is will ok? > > 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. >-- 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 26, 7:52 am, Ar Chron <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> amritpal p. wrote in post #995086: > > > Stuff... > > You seem to be lacking some fundamental "organizational" knowledge as it > pertains to a Rails application. > > What I found very instructive way back when was to scaffold a basic > application and see what Rails created, and how it was organized. Then > I fiddled with that scaffolded application, one change at a time. > > If you have an existing application, you can just add a scaffolded > model, controller, and views via: > > rails g scaffold person first_name:string last_name:string > > (doesn''t have to be person, could be anything, just give it a model name > and some attributes with types). > > Then look at the controller, model, and views that are created. Most > enlightening.Yes i have tried scafffolding.But i want to generate a form without scaffold.i want to manualy create a controller,view and model for it.please help to do 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 26, 7:53 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 26 Apr 2011, at 12:28, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > > > On Apr 26, 5:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On Apr 26, 10:21 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > >> wrote: > > >>> is it saying @book variablei is nil? > >>> it is defined in controller as : > > >>> class BookController < ApplicationController > >>> def index > >>> @book =Book.new > >>> end > >>> end > > >> Your index action defines @book, but you''re testing the "new" action. > > Correspond to index action i have index file which > > hold following code and i can access this file successfully but when i > > click on "New book",it gives the error > > Yes, we know that. What you don''t seem to grasp is that because the new page is being displayed the index method isn''t called (the new method, if it exists will be called) so @book isn''t setyou mean i should make a another method "new" inside controller and "@book =Book.new" should be written there? Amrit pal -- 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 26, 1:35 pm, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > you mean i should make a another method "new" inside > controller and "@book =Book.new" should be written there? >Yes. Seriously, give the scaffolds a go, even if you don''t want to use them for your finished product (which is fair enough), you''d at least get a vague idea of what goes where and what things need to be done. 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.
amritpal p. wrote in post #995096:> Yes i have tried scafffolding.But i want to generate a form > without scaffold.i want to manualy create a controller,view and model > for it.please help to do it. > > ThanksYes, fair enough. But use the scaffolded elements as the prototype for your manual creations... If you have scaffolded something, then the "right way" (or at least the way that follows the Rails conventions most cleanly) is there in front of you. Suppose you want a book model. 1. You''ll need a books_controller. By conventions: - the index method in the controller retrieves all the books into a variable named @books. - the show method retrieves a single existing book stored into a variable named @book according to an id received in the params - the new method created a new book, named @book via a simple @book = Book.new - the edit method also retrieves a single existing book stored into a variable named @book according to an id received in the params - the create method receives a book definition via params and creates a new @book instance from the values contained in the params, then attempts to persist that object in the DB. - the update method retrieves an existing book via a find using the id received in the params, then updates that books attributes with those also received in the params. - destroy finds a book according to the id received in the params, and, well, deletes it. Each of these controller methods, be default, will have its results rendered in a view named according to the method that the view supports. - index method renders its output via the index.html.erb - new and edit render via new.html.erb and edit.html.erb, each of which uses a partial named _form.html.erb (and yes, that underscore at the beginning of the filename is important). If you are creating your own, then don''t forget to update the routes.rb when you add a new model and controller, or action to an existing model/controller. All of this is readily apparent from a study of a scaffolded solution, and a little reading. -- 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 Apr 26, 8:35 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 26, 7:53 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > > > > > On 26 Apr 2011, at 12:28, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Apr 26, 5:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> On Apr 26, 10:21 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> wrote: > > > >>> is it saying @book variablei is nil? > > >>> it is defined in controller as : > > > >>> class BookController < ApplicationController > > >>> def index > > >>> @book =Book.new > > >>> end > > >>> end > > > >> Your index action defines @book, but you''re testing the "new" action. > > > Correspond to index action i have index file which > > > hold following code and i can access this file successfully but when i > > > click on "New book",it gives the error > > > Yes, we know that. What you don''t seem to grasp is that because the new page is being displayed the index method isn''t called (the new method, if it exists will be called) so @book isn''t set > > you mean i should make a another method "new" inside > controller and "@book =Book.new" should be written there? >Awaiting your helpful reply!! -- 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.
Awaiting your helpful reply!! -- 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.
> amritpal p. wrote in post #995333: > > Awaiting your helpful reply!!You''ve already got an answer - your ''@book'' method is undefined in the ''new'' action of your controller. You need to define ''@book'' in ''new'' before you can access it. When an object such as a variable is undefined, it will return nil which is what you''re seeing. -- 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 Apr 26, 8:35 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 26, 7:53 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > > > > > > > > > On 26 Apr 2011, at 12:28, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On Apr 26, 5:55 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > wrote: > > >> On Apr 26, 10:21 am, amrit pal pathak <amritpalpath...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > >> wrote: > > > >>> is it saying @book variablei is nil? > > >>> it is defined in controller as : > > > >>> class BookController < ApplicationController > > >>> def index > > >>> @book =Book.new > > >>> end > > >>> end > > > >> Your index action defines @book, but you''re testing the "new" action. > > > Correspond to index action i have index file which > > > hold following code and i can access this file successfully but when i > > > click on "New book",it gives the error > > > Yes, we know that. What you don''t seem to grasp is that because the new page is being displayed the index method isn''t called (the new method, if it exists will be called) so @book isn''t set > > you mean i should make a another method "new" inside > controller and "@book =Book.new" should be written there?Awaiting your helpful reply!! -- 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.