什么';这个RubyonRails&;jQuery代码?

什么';这个RubyonRails&;jQuery代码?,jquery,ruby-on-rails,ruby,ajax,Jquery,Ruby On Rails,Ruby,Ajax,因此,我正在构建一个应用程序,让用户粘贴视频的url,然后使用嵌入式jquery API输出缩略图。然后,单击缩略图时,将显示嵌入的视频 但是,我的控制器中出现以下错误: NoMethodError in VideosController#create You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occu

因此,我正在构建一个应用程序,让用户粘贴视频的url,然后使用嵌入式jquery API输出缩略图。然后,单击缩略图时,将显示嵌入的视频

但是,我的控制器中出现以下错误:

NoMethodError in VideosController#create

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.save
def new
  @video = Video.new
end

def create
  @video = Video.new(params[:video])

  respond_to do |format|
    if @article.save
      format.html #{ redirect_to(@video, :notice => 'Article was successfully created.') }
    else
      format.html { render :action => "new" }
    end
  end
end
这是我的视频控制器:

NoMethodError in VideosController#create

You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.save
def new
  @video = Video.new
end

def create
  @video = Video.new(params[:video])

  respond_to do |format|
    if @article.save
      format.html #{ redirect_to(@video, :notice => 'Article was successfully created.') }
    else
      format.html { render :action => "new" }
    end
  end
end
这是我的application.js文件:

$(document).ready(function() {

$("li a").embedly({}, function(oembed, dict){
  if ( oembed == null)
    return;
  var output = "<a class='embedly' href='#'><img src='"+oembed.thumbnail_url+"' /></a><span>"+oembed.title+"</span>";
  output += oembed['code'];
    $(dict["node"]).parent().html( output );
});
   $('a.embedly').live("click", function(e){
    e.preventDefault();
    $(this).parents('li').find('.embed').toggle();
  });
});
我做错了什么?我接下来需要采取什么步骤来实现这一目标


附带说明:我包含了所有必要的文件。

在您试图保存的视频控制器中
@article
。您想将
@video

保存在您试图保存
@article
的视频控制器中。您想保存
@video

def create
  @video = Video.new(params[:video])

  respond_to do |format|
    if @article.save
视频还是文章


视频或文章?

这意味着您没有
create.html.erb
视图。在这一点上,我们真的陷入了一个与您原来的问题不同的问题。这是因为您可能没有创建操作的视图。实际上,大多数人都会重定向到显示记录的操作(例如,显示、索引或您喜欢的任何内容)。是的,我意识到了这一点,所以我只是在控制器中使用
format.html{render:action=>“new”}
重定向回
new
视图。但是,现在视频的缩略图不会出现。这里有一个链接,上面写着“视频”,可以把你带到youtube视频;您将希望对ajax请求返回与“正常”http请求不同的响应。您可以返回一个html片段或一些json,以便在客户端使用。是的,所以我在控制器中执行类似
format.js
format.json
的操作?我应该返回的html片段是什么?很抱歉,这意味着您没有
create.html.erb
视图。在这一点上,我们真的陷入了一个与您原来的问题不同的问题。这是因为您可能没有创建操作的视图。实际上,大多数人都会重定向到显示记录的操作(例如,显示、索引或您喜欢的任何内容)。是的,我意识到了这一点,所以我只是在控制器中使用
format.html{render:action=>“new”}
重定向回
new
视图。但是,现在视频的缩略图不会出现。这里有一个链接,上面写着“视频”,可以把你带到youtube视频;您将希望对ajax请求返回与“正常”http请求不同的响应。您可以返回一个html片段或一些json,以便在客户端使用。是的,所以我在控制器中执行类似
format.js
format.json
的操作?我应该返回的html片段是什么?很抱歉,我的问题是noob,哈哈