我总是收到这个错误,我不明白我错在哪里。我想我在控制器中拥有我需要操作的一切、路由文件中的资源和控制器操作的视图。current_events/new
当我收到此错误时,我将路线放在浏览器中。我也尝试一下resources :current_events
输出rake routes
:
current_events GET /current_events(.:format) current_events#index
new_current_event GET /current_events/new(.:format) current_events#new
current_event GET /current_events/:id(.:format) current_events#show
config/routes.rb
:
appname::Application.routes.draw do
devise_for :users, controllers: { omniauth_callbacks: "omniauth_callbacks"}
resources :current_events, only: [:show, :new, :index]
end
CurrentEventsController
:
class CurrentEventsController < ApplicationController def index @current_event = CurrentEvent.all respond_to do |format| format.html format.json { render json: @current_event } end end def create @current_event = CurrentEvent.new(params[:current_event]) respond_to do |format| if @current_event.save format.html { redirect_to @current_event, notice: 'current event was created.' } format.json { render json: @current_event, status: :created, location: @current_event } else format.html { render action: "new" } format.json {render json: @current_event.errors, status: :unprocessable_entity} end end end def new @current_event = CurrentEvent.new respond_to do |format| format.html format.json { render json: @current_event } end end def edit @current_event = CurrentEvent.find(params[:id]) end def destroy @current_event = CurrentEvent.find(params[:id]) @current_event.destroy respond_to do |format| format.html { redirect_to current_event_url} format.json { head :no_content } end end def show @current_event = CurrentEvent.find(params[:id]) respond_to do |format| format.html format.json{ render json: @current_event} end end end