简体   繁体   中英

Why am I getting this error with my RoR app?

I get this error:

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>

I have one Video model and a videos controller with a new and create method. My routes.db file has root :to => "videos#new" . I have one view new.html.erb with this code:

<%= 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 %>

And my controller has this:

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

This is all that's in my routes file:

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

your routes should be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM