Weird error with User edit view

时间秒杀一切 提交于 2019-12-11 20:42:46

问题


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 indexview. 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.errors.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>

回答1:


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.



来源:https://stackoverflow.com/questions/5415358/weird-error-with-user-edit-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!