stranger
(stranger)
January 21, 2008, 10:22pm
1
Hello everyone,
I am following the Practical Rails: Social Networking
sites book. In chapter 7 photo gallery I am getting a
NoMethodError in Pages#show
Showing layouts/_menu.rhtml where line #12 raised:
undefined method `new_entry_path' for #<ActionView::Base:0x52fa56c>
Extracted source (around line #12 ):
9: <% if is_logged_in? %>
10: <li>Logged in as: <i><%= logged_in_user.username %></i></li>
11: <li><%= link_to 'My Profile', edit_user_path(logged_in_user)
%></li>
12: <li><%= link_to 'New Blog Post', new_entry_path(:user_id =>
logged_in_user) -%></li>
13: <li><%= link_to 'Upload Photo', user_new_photo_path(:user_id
=> logged_in_user) -%></li>
14: <li><%= link_to 'Logout', {:controller => 'account', :action
=> 'logout'}, :method => :post %></li>
15: <% else %>
I am using rails 2.0.2 over windows vista. Can someone please explain
me whats wrong?
radar
(Ryan Bigg)
January 21, 2008, 10:29pm
2
Do you have a controller named entries? Do you have a route set up for it:
map.resources :entries
stranger
(stranger)
January 21, 2008, 10:34pm
3
Ya I have a 'entries_controller.rb' where index, new create, edit and
destroy are defined. and in routes.rb
map.resources :articles, :collection => {:admin => :get}
stranger
(stranger)
January 21, 2008, 10:49pm
4
map.resources :users, :member => { :enable => :put } do |users|
users.resources :roles
users.resources :entries do |entry|
entry.resources :comments
end
users.resources :photos, :name_prefix => 'user_', :controller =>
'user_photos'
end
map.resources :articles, :collection => {:admin => :get}
This is the 'entries' in config.rb. I am creating a new blog post that
is entry...
stranger
(stranger)
January 22, 2008, 4:05am
5
I'm sorry for the late reply....I am still getting the same error.
<% if is_logged_in? %>
<li>Logged in as: <i><%= logged_in_user.username %></i></li>
<li><%= link_to 'My Profile', edit_user_path(logged_in_user) %></
<li><%= link_to 'New Blog Post', new_entry_path(:user_id =>
logged_in_user) -%></li>
<li><%= link_to 'Upload Photo', user_new_photo_path(:user_id =>
logged_in_user) -%></li>
<li><%= link_to 'Logout', {:controller => 'account', :action =>
'logout'}, :method => :post %></li>
<% else %>
<li><%= link_to 'Signup', :controller => 'users', :action => 'new'
%></li>
<li><%= link_to 'Login', :controller => 'account', :action =>
'login' %></li>
<% end %>
When I try to reach the page without logging I am able to see the
localhost:3000/photos and index. But when I login and the above block
of code gets executed I am getting the error.
undefined method `new_entry_path' for #<ActionView::Base:0x50d9f6c>
radar
(Ryan Bigg)
January 22, 2008, 4:20am
6
Because you’re STILL calling new_entry_path when I told you it should be new_user_entry_path(@user )
either that or define map.resources :entries inside of your routes.rb outside of the user block.