我一直在," NoMethodError(未定义的方法`时刻'对于nil:NilClass):"

时间:2016-03-13 02:33:50

标签: ruby-on-rails ruby api

我刚刚开始学习ruby并且我正在编写一个简单的API,但是我遇到了错误NoMethodError(未定义的方法Rails.application.routes.draw do resources :posts devise_for :users namespace :api do namespace :v1 do devise_scope :user do post 'registrations' => 'registrations#create', :as => 'register' post 'sessions' => 'sessions#create', :as => 'login' delete 'sessions' => 'sessions#destroy', :as => 'logout' end get 'moments' => 'moments#index', :as => 'moments' post 'moments' => 'moments#create' end end devise_scope :user do get '/users/sign_out' => 'devise/sessions#destroy' end end` 索引'这是一个代码:

class Api::V1::MomentsController < ApplicationController
  skip_before_filter :verify_authenticity_token,
                     :if => Proc.new { |c| c.request.format == 'application/json' }

  before_filter :authenticate_user!

  def index
    @moments = current_user.moments
  end

  def create

    @moment = current_user.moments.build(params[:moment])

    if @moment.save
       @moment
    else
      render :status => :unprocessable_entity,
             :json => { :success => false,
                        :info => @moment.errors,
                        :data => {} }
    end
  end

  #private
   # def moment_params
   #   params.require(:moment).permit(:title, :completed)
   # end

end

此处代码:moments_controller.rb

\Illuminate\Session\Middleware\StartSession

任何人都可以看到我的代码出了什么问题吗?

0 个答案:

没有答案