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

uninitialized constant Comment::Create::CRUD (NameError) #21

Open
agm1988 opened this issue Aug 6, 2016 · 1 comment
Open

uninitialized constant Comment::Create::CRUD (NameError) #21

agm1988 opened this issue Aug 6, 2016 · 1 comment

Comments

@agm1988
Copy link

agm1988 commented Aug 6, 2016

I am follow chapter 5 of the book

app/concepts/comment/operation.rb

class Comment < ActiveRecord::Base
  class Create < Trailblazer::Operation
    include CRUD
    model Comment, :create

    contract do
      property :body
      property :weight
      property :thing
      validates :body, length: { in: 6..160 }
      validates :weight, inclusion: { in: ["0", "1"] }
      validates :thing, :user, presence: true

      property :user do
        property :email
        validates :email, presence: true, email: true
      end
    end

    def process(params)
      validate(params[:comment]) do |f|
        f.save
      end
    end
    private
    def setup_model!(params)
      model.thing = Thing.find_by_id(params[:thing_id])
    end
  end
end

config/initializers/trailblazer.rb

require 'trailblazer/autoloading'

require "trailblazer/operation/dispatch"

Trailblazer::Operation.class_eval do
  include Trailblazer::Operation::Dispatch
end

require "roar/decorator"
require "roar/json/hal"

::Roar::Representer.module_eval do
  include Rails.application.routes.url_helpers
  # include Rails.app.routes.mounted_helpers

  def default_url_options
    {}
    end
end
@apotonick
Copy link
Owner

Hi, are you reading the most recent version? CRUD has been renamed to Model and I'm a 100% sure I changed all occurrences in the book, many months ago. Let me know if that doesn't fix it for you.

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

No branches or pull requests

2 participants