我從來沒有見過這樣的錯誤消息之前未定義的方法軌
undefined method `new' for Book:Module
,並想知道是否有人知道爲什麼我得到它,我首先想到的是命名約定,但我不確定
我有一個模塊
module Book::BookFinder
BOOK_URL = 'https://itunes.apple.com/lookup?isbn='
def book_search(search)
response = HTTParty.get(BOOK_URL + "#{search}", :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' })
results = JSON.parse(response.body)["results"]
end
end
,然後包括它在我的控制之內
class BookController < ApplicationController
before_filter :authenticate_admin_user!
include Book::BookFinder
def results
results = book_search(params[:search])
@results = results
@book = Book.new
@book.author = results[0]["artistName"]
end
def create
@book = Book.new(params[:book])
if @book.save
redirect_to @book, notice: 'Book was successfully saved'
else
render action:new
end
end
end
有沒有人碰到這個纔來知道如何解決它?
感謝
模塊不能被實例化REF: - 。http://marakana.com/bookshelf/ruby_tutorial /modules.html – Salil