How to generate the scaffold by user defined path

5 views
Skip to first unread message

hitme

unread,
Dec 4, 2009, 11:25:15 AM12/4/09
to Ruby on Rails: Talk
when I use
ruby script/generate scaffold publisher name:string
It's worked correctly.

when I use:
ruby script/generate scaffold Admin::publisher name:string
The command done and no error.
Then I add the following code into routes.rb

map.namespace :admin do |admin|
admin.resources :publishers
end

The url http://127.0.0.1:3000/admin/publisher/new was correct.
but when I push the 'create' button.There is a error message:

######################################################
NoMethodError in Admin/publishers#index

Showing app/views/admin/publishers/index.html.erb where line #8
raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Extracted source (around line #8):

5: <th>Name</th>
6: </tr>
7:
8: <% @publishers.each do |publisher| %>
9: <tr>
10: <td><%=h publisher.name %></td>
11: <td><%= link_to 'Show', publisher %></td>
######################################################

And there is no new item insert into database.

Why?~

Colin Law

unread,
Dec 4, 2009, 12:31:20 PM12/4/09
to rubyonra...@googlegroups.com
2009/12/4 hitme <yyha...@gmail.com>:
The error means what it says, that @publishers is nil. Presumably
something has gone wrong in your create method. Have a look in the
log (log/development.log) to see if you get any clues. Otherwise you
could debug into create and see what is happening. Have a look at the
rails guide on debugging (http://guides.rubyonrails.org/) and also the
Getting Started guide if you have not already worked through that.

Colin
Reply all
Reply to author
Forward
0 new messages