简体   繁体   English

未定义的方法“变形虫”导轨 5.2

[英]undefined method `amoeba' rails 5.2

I'm following this tutorial for implementing a bookingsystem to my rails app.我正在按照本教程为我的 Rails 应用程序实现预订系统。 I'm currently stuck, because when I hit the 'New booking' button I get this error我目前卡住了,因为当我点击“新预订”按钮时,我收到了这个错误

undefined method `amoeba' for #<Class:0x00007fa37f7862a0>

![NoMethodError in BookingsController#create ] 1 ![BookingsController#create 中的 NoMethodError ] 1

I have included gem 'amoeba' in my gem file, but it still doesn't work.我在我的 gem 文件中包含了 gem 'amoeba',但它仍然不起作用。 Anyone know how to fix it?谁知道怎么修它? It would be very much appreciated.将不胜感激。

schedule.rb日程表

class Schedule < ApplicationRecord

  # Tenant Of
  belongs_to :account, :inverse_of => :schedules
  accepts_nested_attributes_for :account

  belongs_to :practitioner, :inverse_of => :schedules
  accepts_nested_attributes_for :practitioner

  has_many :bookings, :inverse_of => :schedule
  accepts_nested_attributes_for :bookings

  validates :start, uniqueness: { scope: :practitioner_id, message: "You have already made this time available" }

  amoeba do
    enable
    exclude_associations :bookings
  end

end

bookings_controller.rb预订控制器.rb

class BookingsController < ApplicationController
  before_action :set_booking, only: [:show, :edit, :update, :destroy]

  # GET /bookings
  # GET /bookings.json
  def index
    @bookings = Booking.all
  end

  # GET /bookings/1
  # GET /bookings/1.json
  def show
  end

  # GET /bookings/new
  def new
    @booking = Booking.new
  end

  # GET /bookings/1/edit
  def edit
  end

  # POST /bookings
  # POST /bookings.json
  def create
    @booking = Booking.new(booking_params)

    respond_to do |format|
      if @booking.save
        format.html { redirect_to @booking, notice: 'Booking was successfully created.' }
        format.json { render :show, status: :created, location: @booking }
      else
        format.html { render :new }
        format.json { render json: @booking.errors, status: :unprocessable_entity }
      end
    end
  end

  # PATCH/PUT /bookings/1
  # PATCH/PUT /bookings/1.json
  def update
    respond_to do |format|
      if @booking.update(booking_params)
        format.html { redirect_to @booking, notice: 'Booking was successfully updated.' }
        format.json { render :show, status: :ok, location: @booking }
      else
        format.html { render :edit }
        format.json { render json: @booking.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /bookings/1
  # DELETE /bookings/1.json
  def destroy
    @booking.destroy
    respond_to do |format|
      format.html { redirect_to bookings_url, notice: 'Booking was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_booking
      @booking = Booking.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def booking_params
      params.require(:booking).permit(:status, :title, :cost, :start, :cancellation_reason, :refunded, :practitioner_id, :schedule_id, :lesson_id, :account_id)
    end
end

Log日志

Started POST "/bookings" for ::1 at 2020-03-23 12:42:06 +0100
Processing by BookingsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"IE78VI28UqOkuhXUnyY5bdvsN1S4wHw38Uu5BTZ+7ZdT0+6Ii50EThTELTiUWHuQOsOjy+MO4Dw6HyOwxJwWEw==", "booking"=>{"status"=>"Testing", "title"=>"Testing title", "cost"=>"3", "start(1i)"=>"2020", "start(2i)"=>"3", "start(3i)"=>"23", "start(4i)"=>"11", "start(5i)"=>"39", "cancellation_reason"=>"", "refunded"=>"0", "practitioner_id"=>"2", "schedule_id"=>"-1", "lesson_id"=>"2", "account_id"=>"1"}, "commit"=>"Create Booking"}
  User Load (1.4ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 104 ORDER BY `users`.`id` ASC LIMIT 1
  ↳ /Users/kaspervalentin/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/activerecord-5.2.4.1/lib/active_record/log_subscriber.rb:98
   (0.3ms)  BEGIN
  ↳ app/controllers/bookings_controller.rb:30
  Account Load (0.4ms)  SELECT  `accounts`.* FROM `accounts` WHERE `accounts`.`id` = 1 LIMIT 1
  ↳ app/controllers/bookings_controller.rb:30
  Lesson Load (0.4ms)  SELECT  `lessons`.* FROM `lessons` WHERE `lessons`.`id` = 2 LIMIT 1
  ↳ app/controllers/bookings_controller.rb:30
   (0.3ms)  ROLLBACK
  ↳ app/controllers/bookings_controller.rb:30
Completed 500 Internal Server Error in 63ms (ActiveRecord: 2.8ms)



NoMethodError (undefined method `amoeba' for #<Class:0x00007fa37f7862a0>):

app/models/schedule.rb:15:in `<class:Schedule>'
app/models/schedule.rb:1:in `<main>'
app/controllers/bookings_controller.rb:30:in `block in create'
app/controllers/bookings_controller.rb:29:in `create'

首先尝试从ActiveRecord::Base继承您的模型类,当您在模型中使用变形虫时,您可以避免在amoeba do调用的enable方法amoeba do block 因为如果您使用诸如include_association之类的东西,则不需要编写enableexclude_association

在 Rails 升级到 5.2 和 ruby 到 2.5.7 后,# <http::client error in my rails project< div><div id="text_translate"><p> 在 rails 升级到 5.2 版和 ruby 到 2.5.7 之后,我的 rails 项目出现以下错误,我也升级了faraday gem,但无法解决这个问题。 任何帮助都是可取的。</p><pre> NoMethodError: undefined method `prepend' for #&lt;HTTP::Client:0x00007ff4dc21a470&gt; Did you mean? present?</pre></div></http::client> - After Rails Upgrade to 5.2 and ruby to 2.5.7 getting undefined method `prepend' for #<HTTP::Client error in my rails project

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails 5.2继承类中的未定义方法belongs_to - Rails 5.2 Undefined method belongs_to in inherited class Rails 5.2部分计数器:“未定义的局部变量或方法”错误 - Rails 5.2 partial counter: “undefined local variable or method” error Rails 5.2 上的 Ruby - NoMethodError(nil:NilClass 的未定义方法“主机”): - Ruby on Rails 5.2 - NoMethodError (undefined method `host' for nil:NilClass): Rails 4,关注的变形虫宝石 - Rails 4, Amoeba Gem inside a Concern Rails + Amoeba错误:未初始化的常量 - Rails + Amoeba error: Uninitialized constant Rails 5.2在凭据中保存方法? - Rails 5.2 save method in credentials? 如何使用变形虫宝石在铁轨中复制图像? - How to copy images using amoeba gem in rails? 在 Rails 升级到 5.2 和 ruby 到 2.5.7 后,# <http::client error in my rails project< div><div id="text_translate"><p> 在 rails 升级到 5.2 版和 ruby 到 2.5.7 之后,我的 rails 项目出现以下错误,我也升级了faraday gem,但无法解决这个问题。 任何帮助都是可取的。</p><pre> NoMethodError: undefined method `prepend' for #&lt;HTTP::Client:0x00007ff4dc21a470&gt; Did you mean? present?</pre></div></http::client> - After Rails Upgrade to 5.2 and ruby to 2.5.7 getting undefined method `prepend' for #<HTTP::Client error in my rails project 在将 Rails 从 4.1 更新到 5.2 并添加响应者 gem 后,为我的控制器获取“未定义的方法`flash`” - Getting "undefined method `flash`" for my controllers after updating Rails from 4.1 to 5.2 and added the responders gem 简单更新方法上的Rails 5.2语法错误 - Rails 5.2 Syntax Error on Simple Update Method
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM