Question

I can't seem to get the button to open the url in a browser. The script runs in Shoes, however the button does not do anything. What am I doing wrong?

Shoes.setup do
  gem 'launchy'
end

require 'launchy'

Shoes.app do
    background "#EFC"
    border("#BE8",
           strokewidth: 6)

    stack(margin: 12) do
      para "Enter ID"
      flow do
        @e = edit_line

        id = @e.text

        fburl = "http://www.facebook.com/profile.php?id="

        #alert fburl+id

        button "OK" do
        Launchy.open("#{fburl}+#{id}")



      end
    end
  end
end

After making the suggested changes and using "shoes.setup do", I get the following error:

undefined method 'dir for Gem:Module :344:in 'method_missing' C:/Program Files (x86)/Common Files/Shoes/O.r1514/ruby/lib/rubygems/installer.rb:97:in 'initialize' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes/setup.rb:265:in 'new' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes/setup.rb:265:in 'install_sources' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes/setup.rb:27:in 'init C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes/setup.rb:329:in '' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes.rb:105:in 'require' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes.rb:105:in 'setup' Shoes Gem Loader.rb:1:in '' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes.rb:428:in 'eval' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes.rb:428:in 'visit' C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes.rb:118:in 'show_selector C:/Program Files (x86)/Common Files/Shoes/O.r1514/lib/shoes.rb:151:in 'block (4 levels in splash' (null):0:in 'call'

Am I to assume that launchy is not a usable gem in Shoes?

Was it helpful?

Solution

The "original" Shoes doesn't play well with gems. The newest version of Shoes (Shoes 4) lets you require gems normally. It's pre-alpha, but almost feature-complete. Here's your code modified to run in Shoes 4. Note that the id assignment has to be moved into the button block (but this would be necessary for any version of Shoes)

require 'launchy'

Shoes.app do
  background "#EFC"
  border("#BE8", strokewidth: 6)

  stack(margin: 12) do
    para "Enter ID"
    flow do
      @e = edit_line

      fburl = "http://www.facebook.com/profile.php?id="

      button "OK" do
        id = @e.text
        alert fburl+id
        Launchy.open("#{fburl}+#{id}")
      end
    end
  end
end

To install Shoes 4, follow the instructions on GitHub, and make sure you gem install launchy. Then you should be able to run your app.

OTHER TIPS

It's because Red shoes is has different (independent) Ruby installation so gems are in the different folder.

In order to use gems you should do this:

Shoes.setup do
  gem 'launchy'
end

ps. it still may not work if gem you are using is not compatible, as fair I remember, with Ruby 1.9.1.
Red shoes is using this version on my computer. I'm not sure about other operating systems though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top