簡體   English   中英

為什么我的RoR應用程序出現此錯誤?

[英]Why am I getting this error with my RoR app?

我收到此錯誤:

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>

我有一個Video模型和一個帶有newcreate方法的video控制器。 我的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

你的路線應該是

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM