用户编辑视图的奇怪错误 [英] Weird error with User edit view

查看:47
本文介绍了用户编辑视图的奇怪错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我收到此错误:

用户中没有方法错误#edit显示第 3 行提出的/rubyprograms/dreamstill/app/views/videos/_modal.html.erb:NilClass:Class 的未定义方法`model_name'提取的源代码(围绕第 3 行):1:<div id="boxes">2:<div id="dialog" class="window">3: <%= form_for(@video) 做 |f|%>

这与我渲染到 index 视图中的名为 _modal 的部分有关.它里面有一个表格.

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

def 索引@video = Video.new@videos = Video.paginate(:page => params[:page], :per_page => 20)结尾

为什么我会收到此错误,我该如何解决?

更新:

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

def 编辑@user = current_user结尾

这是 _modal 部分:

<div id="dialog" class="window"><%= form_for(@video) 做 |f|%><% 如果@video.errors.any?%><div id="错误解释"><h2><%=pluralize(@video.errors.count, "error") %>禁止保存此视频:</h2><ul><% @video.errors.full_messages.each 做 |msg|%><li><%=msg%></li><%结束%>

<%结束%><div class="field"><%= f.label :video_url %><br/><%= f.text_field :video_url %>

<div class="field"><%= f.label :title, '歌曲名'%><br/><%= f.text_field :title %>

<div class="actions"><%= f.submit %>

<%结束%><%= link_to '取消', '#', :class =>'关闭' %>

<div id="掩码"></div>

解决方案

相信你的问题和上次基本一样.

由于您正在有效地呈现 edit 操作——无论它是否在模态中——您需要再次定义 @video.

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>

解决方案

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.

这篇关于用户编辑视图的奇怪错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆