2011-03-12 78 views
-1

我得到這個錯誤:爲什麼我的RoR應用程序出現此錯誤?

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

顯示您的航線 – fl00r 2011-03-12 21:28:23

+0

確定發佈,這不是很多...這可能是爲什麼我得到這個錯誤? – 2011-03-12 21:30:35

回答

4

你的路線應該是

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

嗯,我其實試過這個,但它沒有工作......但現在它確實。謝謝! – 2011-03-12 21:35:23

+0

關鍵是「資源:視頻」這一行。這就是允許您使用'videos_path','new_video_path'等等。請參閱[here](http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions)以獲取更多信息。 – Zabba 2011-03-12 21:36:05

相關問題