Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting error when trying out camping book section 02 on models #155

Open
verachell opened this issue Jun 27, 2023 · 1 comment
Open

Getting error when trying out camping book section 02 on models #155

verachell opened this issue Jun 27, 2023 · 1 comment

Comments

@verachell
Copy link

Beginner/noob here, following along with the camping book section 02 at https://github.com/camping/camping/blob/master/book/02_getting_started.md I had no problems with the earlier bit on routes and controllers and I tried out my own variations on that too. I then tried the section about models at https://github.com/camping/camping/blob/master/book/02_getting_started.md#modeling-the-world but I keep getting errors. I'm not sure if I've overlooked something obvious in what I'm doing (which is likely!) or if the book documentation has yet to catch up to the new version of camping.

Here is my code:

Camping.goes :Stuff

module Stuff::Models
  class Page < Base
  end

  class BasicFields < V 1.0
    def self.up
      create_table Page.table_name do |t|
        t.string :title
        t.text   :content
        # This gives us created_at and updated_at
        t.timestamps
      end
    end

    def self.down
      drop_table Page.table_name
    end
  end
end

def Stuff.create
  Stuff::Models.create_schema
end

Here is my Gemfile:

# frozen_string_literal: true
source 'https://rubygems.org'

gem 'camping'
gem 'tilt'
gem 'activerecord'
gem 'acts_as_versioned'

group :test do
  gem 'minitest', '~> 5.0'
  gem 'minitest-reporters'
  gem 'rack-test'
  gem 'ruby_parser'
  gem 'minitest-hooks'
end

Here are the errors:

camp.rb:4:in `<module:Models>': uninitialized constant Stuff::Models::Base (NameError)

  class Page < Base
               ^^^^
Did you mean?  Base64
	from camp.rb:3:in `<top (required)>'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/camping-3.1.3/lib/camping/loader.rb:132:in `load'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/camping-3.1.3/lib/camping/loader.rb:132:in `load_file'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/camping-3.1.3/lib/camping/loader.rb:88:in `load_everything'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/camping-3.1.3/lib/camping/loader.rb:163:in `reload!'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/camping-3.1.3/lib/camping/server.rb:131:in `start'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/rackup-2.1.0/lib/rackup/server.rb:182:in `start'
	from /home/family/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/camping-3.1.3/bin/camping:10:in `<top (required)>'
	from /home/family/.rbenv/versions/3.2.2/bin/camping:25:in `load'
	from /home/family/.rbenv/versions/3.2.2/bin/camping:25:in `<main>'

Am I missing a gem or doing something wrong? I re-did bundle install. I tried using camping camp.rb and bundle exec camping -e development and the errors are similar in both (not identical but both start similarly by complaining about class Page < Base )

@karloscarweber
Copy link
Member

This is definitely a case where the book is outdated and needs to catch up. We removed ActiveRecord as a hard dependency from Camping earlier this, in favor of Camping Gear that adds the database bindings back in. It's just that those bindings haven't shipped yet and are still in development.

I think the quickest course of action would actually be to use the Sequel Gem to handle Database stuff for now. It has a smaller overhead to get working with a generic ruby project than ActiveRecord currently has.

Once again, We'll be adding easy ActiveRecord and Sequel Gem support to Camping this summer, and you're efforts to get it working could jump start that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants