Ruby on Rails:显示F:/RubyRails/Febdos/app/views/noticias/_form.html.erb,其中第1行引发

时间:2015-12-16 13:46:27

标签: ruby-on-rails

我努力了,我不知道为什么会收到这个错误:

  

Noticias中的NoMethodError #new

     

显示F:/RubyRails/Febdos/app/views/noticias/_form.html.erb其中   第1行提出:

     

未定义的方法`noticia_index_path'对

     

<#:0x6c19d88>

     

提取的来源(第1行):

     

<%= form_for(@noticia)do | x | %GT;

            <%= x.label:titulo%>

     

模板包含跟踪:app / views / noticias / new.html.erb

     

Rails.root:F:/ RubyRails / Febdos

这是我的_form.html.erb

<%= form_for(@noticia) do|x| %>
<p>

    <%= x.label :titulo %><br>
    <%= x.text_field :titulo %>
</p>

<p>
    <%= x.label :descripcion %><br>
    <%= x.text_area :descripcion %>
</p>
<p>
    <%= x.label :fecha %><br>
    <%= x.text_field :fecha %>
</p>
<br>

    <%= x.submit :"Crear Producto" %>

<% end %>

我的控制器

class NoticiasController < ApplicationController
  def index
    @prods= Noticia.all
  end

  def new
    @noticia=Noticia.new  
  end
  # para crear la clase producto 
  def create
    @noticia=Noticia.new(noticia_params)
    if @noticia.save
      redirect_to root_path
    else
      "Error al crear el producto"
    end

  end

  def edit
    @noticia =Noticia.find(params[:id])


  end

  def update
    @noticia =Noticia.find(params[:id])

    if @noticia.update_attributes(noticia_params)
      redirect_to root_path
    else
      "Error al editar"
    end
  end
def destroy
    @noticia= Noticia.find(params[:id])
    if @noticia.destroy
      redirect_to root_path
    else
      "error al borrar"
    end
  end

  def show
     @noticia =Noticia.find(params[:id])
  end

  def _form

  end
  # Metodo privado 
  private 
  def noticia_params
    params.require(:noticia).permit(:titulo, :descripcion, :fecha)

  end


end

我的路线

Rails.application.routes.draw do
  #get 'noticias/index'
  #get 'noticias/new'

  #get 'noticias/create'

  #get 'noticias/edit'

  #get 'noticias/show'

  #get 'noticias/_form'
  resources :noticias
  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  root 'noticias#index'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'

0 个答案:

没有答案