Search code examples
rubyshoes

Issue with Shoes setup


When i am running shoes.rb file, which contains code to install gem, it throws error.

Undefined method setup for Shoes:Class

Code:

Shoes.setup do
  gem 'activerecord' # install AR if not found

  require 'active_record'
  require 'fileutils'

  ActiveRecord::Base.establish_connection(
    :adapter   => 'postgresql',
    :dbfile    => 'shoes_app'
  )

  # create the db if not found
  unless File.exist?("shoes_app.sqlite3")
    ActiveRecord::Schema.define do
      create_table :notes do |t|
        t.column :message, :string
      end
    end
  end

end

class ShoesApp < Shoes
  require 'note'

  url '/', :index

  def index
    para 'Say something...'
    flow do
      @note = edit_line
      button 'OK' do
        Note.new(:message => @note.text).save
        @note.text = ''
        @result.replace get_notes  
      end
    end
    @result = para get_notes
  end

  def get_notes
    messages = []
    notes = Note.find(:all, :select => 'message')
    notes.each do |foo|
      messages << foo.message
    end
    out = messages.join("n")
  end

end

Shoes.app :title => 'Notes', :width => 260, :height => 350

Solution

  • The problem was using Shoes4, where the setup method was unimplemented.

    Shoes4 now implements Shoes.setup for backwards compatibility reasons but you don't really need it, so it doesn't do anything except for printing a warning that you should rather do gem install gem_name instead of using Shoes.setup.