Weird error with User edit view
When I click on this link in my index
view:
<%= link_to "Edit Password", edit_user_path(current_user) %>
I get this error:
NoMethodError in Users#edit
Showing /rubyprograms/dreamstill/app/views/videos/_modal.html.erb where line #3 raised:
undefined method `model_name' for NilClass:Class
Extracted source (around line #3):
1: <div id="boxes">
2: <div id="dialog" class="window">
3: <%= form_for(@video) do |f| %>
This has to do with a partial called _modal
that I render into the index
view. It has a form in it.
I also have this in my Videos controller:
def index
@video = Video.new
@videos = Video.paginate(:page => params[:page], :per_page => 20)
end
Why am I getting this error, and how can I fix it?
UPDATE:
Here's my edit action in the Users controller:
def edit
@user = current_user
end
Here's the _modal
partial:
<div id="boxes">
<div id="dialog" class="window">
<%= form_for(@video) do |f| %>
<% if @video.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@video.errors.count, "error") %> prohibited this video from being saved:</h2>
<ul>
<% @video.error开发者_开发问答s.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :video_url %><br />
<%= f.text_field :video_url %>
</div>
<div class="field">
<%= f.label :title, 'Song Title' %><br />
<%= f.text_field :title %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
<%= link_to 'Cancel', '#', :class => 'close' %>
</div>
<div id="mask"></div>
</div>
I believe you are basically having the same problem as last time.
Since you are effectively rendering the edit
action—whether it is in a modal or not—you need @video
defined again.
精彩评论