0
내가 그렇게레이크 작업은
task :create_epubs => :environment do
include Rails.application.routes.url_helpers # brings ActionDispatch::Routing::UrlFor
include ActionView::Helpers::TagHelper
av = ActionView::Base.new(Rails.root.join('app', 'views'))
books = Book.all
av.render("books/", :books => books)
end
같은 레이크 작업에서 Book
라는 모델에 액세스하려고 해요 그러나 나는 다음과 같은 경고를 얻을
rake aborted!
undefined method `to_sym' for nil:NilClass
Tasks: TOP => create_epubs
(See full trace by running task with --trace)
내가로드하기 위해 노력하고있어 모델을 액세스 할 수 다음과 같은 환경 accessing rails models from rake task 레일을 약간 벗어났습니다. 3.1
* 편집 Book.all은 Book.all.to_yaml을 놓으면 무언가를 반환하므로 to_sym 오류가 발생할 수 있습니다. y av.render의 다른 것
나는 문제가 무엇인지 알아 냈다. 내 견해에서 인스턴스 변수를 언급했다.
누구나 그 변수를 설정하여 인스턴스 변수를 계속 사용하는 방법을 알려줄 수 있습니까?
이
내가의 인스턴스 변수를 변경하면 작업 버전 : 변수task :create_epubs => [:environment] do
av = ActionView::Base.new(Rails.root.join('app', 'views'), :assigns => self)
av.view_paths = ActionController::Base.view_paths
av.extend ApplicationHelper #or any other helpers your template may need
book = Book.first
puts av.render(:template => "books/epub-show", :locals => {:book => book}, :layout => false) # this isn't passing @book to the view correctly, i get undefined method for nil:nilClass
end
오류가 발생하는 위치를 확인하기 위해 --trace 옵션을 사용하려는 생각합니다. 그것은 또한 업무 밖에있을 수 있습니다. –
확실히 8 행의 to_sym 오류 –
코드에 to_sym이 표시되지 않습니다 ?? 내가 놓친 게 있니? –