为什么我的RoR应用程序出现此错误?

时间:2011-03-12 21:26:15

标签: ruby-on-rails ruby ruby-on-rails-3

我收到此错误:

NoMethodError in Videos#new

Showing /rubyprograms/dreamstill/app/views/videos/new.html.erb where line #1 raised:

undefined method `videos_path' for #<#<Class:0x10398f8d8>:0x10398dbc8>

我有一个视频模型和一个带有newcreate方法的视频控制器。我的routes.db文件有root :to => "videos#new"。我有一个使用此代码的new.html.erb视图:

<%= 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="actions">
    <%= f.submit %>
  </div>
<% end %>

我的控制器有这个:

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

这就是我的路线档案中的所有内容:

 Dreamstill::Application.routes.draw do
   root :to => "videos#new"
 end

1 个答案:

答案 0 :(得分:4)

你的路线应该是

 Dreamstill::Application.routes.draw do
   root :to => "videos#new"
   resources :videos
 end