用户编辑视图出现奇怪的错误

发布于 2024-10-26 04:46:32 字数 1884 浏览 1 评论 0原文

当我在 index 视图中单击此链接时:

<%= link_to "Edit Password", edit_user_path(current_user) %>

我收到此错误:

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| %>

这与我渲染到 index_modal 的部分有关代码>视图。它有一个形式在里面。

我的视频控制器中也有这个:

def index
  @video = Video.new
  @videos = Video.paginate(:page => params[:page], :per_page => 20)
end

为什么我会收到此错误,如何修复它?

更新:

这是我在用户控制器中的编辑操作:

def edit
  @user = current_user
end

这是 _modal 部分:

<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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行至春深 2024-11-02 04:46:32

我相信您遇到的问题基本上与上次相同。

由于您正在有效地渲染 edit 操作(无论它是否在模态中),因此您需要再次定义 @video

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文