简体   繁体   English

控制器无法识别已安装的宝石

[英]Controller not recognizing installed Gem

Okay, I know this is a bit of a simple question, but I can't seem to get it to work. 好的,我知道这是一个简单的问题,但我似乎无法让它发挥作用。 I have installed the SmarterCSV gem in my Rails 4 app and am trying to use it in my controller like so: 我在我的Rails 4应用程序中安装了SmarterCSV gem,并尝试在我的控制器中使用它,如下所示:

SmarterCSV.process("/files/csv_file.csv")

I can do this exact process in the rails console for this app, but I cannot seem to get it to work in my controller. 我可以在rails控制台中为这个应用程序执行此过程,但我似乎无法让它在我的控制器中工作。 Every time I just get the Rails Dead Screen saying uninitialized constant MyController::SmarterCSV . 每次我只是得到Rails死屏幕说uninitialized constant MyController::SmarterCSV I have tried adding the line 我试过添加该行

require 'smarter_csv'

But that also breaks to the Rails Dead Screen with the error cannot load such file -- smarter_csv 但是这也打破了Rails Dead Screen,错误cannot load such file -- smarter_csv

Any help would be greatly appreciated, Im not entirely sure what I can do... 任何帮助将不胜感激,我不完全确定我能做什么...

您可以尝试使用require 'smarter_csv/smarter_csv'因为这是gem中文件的路径https://github.com/tilo/smarter_csv/blob/master/lib/smarter_csv/smarter_csv.rb

bundle install后不要忘记重新启动应用程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM