【发布时间】:2013-09-11 13:58:50
【问题描述】:
我总是收到这个错误,我不明白我错在哪里。我想我在控制器中拥有我需要操作的一切,路由文件中的资源和控制器操作的视图。当我收到此错误时,我将路由 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
【问题讨论】:
-
你是否在链接中包含了id?
-
我忘了说,我正在尝试转到新页面,所以在浏览器中我说 current_events/new,我会解决我的问题。谢谢!
标签: ruby-on-rails ruby-on-rails-3 routing custom-routes