Cannot require 'nokogiri' in Rails (but works in irb)

后端 未结 2 1787
后悔当初
后悔当初 2021-01-25 20:05

I\'ve just started using Ruby on Rails and so far it\'s working nicely. I\'m now trying to implement a gem but it\'s not working, and I am hoping it\'s just a beginner mistake -

2条回答
  •  盖世英雄少女心
    2021-01-25 20:21

    1. You should put your various require statements outside of your index method. It won't slow you down much to have them in there, but you're asking Ruby to ensure that they are loaded every time the method is called. Better to just require them once at the top of your code. This won't cause your problem, however.

    2. I suspect that you are testing your server under a different environment than what IRB is running in. Try removing the offending require statements for the moment and changing your HTML template to:

      Environment

      • Ruby: <%=RUBY_VERSION%>
      • Gems: <%=`gem list`%>

提交回复
热议问题