Pregunta

I am trying to generate QR codes through the gem qrcode (0.4.2) and having trouble. This is what I have done:

environment.rb

require 'rqrcode'

merchants_controller.rb

def show
 @merchant = Merchant.find(params[:id])
 @qr = RQRCode::QRCode.new( 'my string to generate', :size => 4, :level => :h )

 respond_to do |format|
   format.html # show.html.erb
   format.json { render json: @merchant }
 end
end

show.html.erb

<div class="qr">
    <table>
    <% @qr.modules.each_index do |x| %>
      <tr>  
      <% @qr.modules.each_index do |y| %>
       <% if @qr.dark?(x,y) %>
        <td class="black"/>
       <% else %>
        <td class="white"/>
       <% end %>
      <% end %>
      </tr>
    <% end %>
    </table>
</div>

This is what I get when I initialize the server

    ...
    Exiting
    /Users/andreucasadella/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- rqrcode (LoadError)

    ....
¿Fue útil?

Solución

Remove your require from environment.rb, and try to put gem into the Gemfile:

gem 'rqrcode'

And run $ bundle install and restart server.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top