質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Q&A

解決済

1回答

3621閲覧

ubuntu rails s エラー

Toshinori23

総合スコア19

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

0グッド

0クリップ

投稿2019/07/15 04:11

編集2019/07/15 08:45

railsの環境構築での質問です。
ubuntuでrails の環境構築中rails sとしたところ、エラーが表示されました。

/home/toshiki23/.rbenv/versions/2.5.1/bin/ruby: warning: shebang line ending with \r may cause problems => Booting Puma => Rails 5.1.7 application starting in development => Run `rails server -h` for more startup options Exiting (途中省略) /home/toshiki23/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/factory_bot-5.0.2/lib/factory_bot/definition_proxy.rb:97:in `method_missing': undefined method 'key' in 'ae_param' factory (NoMethodError)

と表示されました。

エラー全文はこちらになります。

以下、definition_proxy.rb、91行目からのコードとなります。

def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissing if args.empty? __declare_attribute__(name, block) elsif args.first.respond_to?(:has_key?) && args.first.has_key?(:factory) association(name, *args) else raise NoMethodError.new( "undefined method '#{name}' in '#{@definition.name}' factory", ) end end

definition_proxy.rbの内容は以下の通りです。

module FactoryBot class DefinitionProxy UNPROXIED_METHODS = %w( __send__ __id__ nil? send object_id extend instance_eval initialize block_given? raise caller method ).freeze (instance_methods + private_instance_methods).each do |method| undef_method(method) unless UNPROXIED_METHODS.include?(method.to_s) end delegate :before, :after, :callback, to: :@definition attr_reader :child_factories def initialize(definition, ignore = false) @definition = definition @ignore = ignore @child_factories = [] end def singleton_method_added(name) message = "Defining methods in blocks (trait or factory) is not supported (#{name})" raise FactoryBot::MethodDefinitionError, message end # Adds an attribute to the factory. # The attribute value will be generated "lazily" # by calling the block whenever an instance is generated. # The block will not be called if the # attribute is overridden for a specific instance. # # Arguments: # * name: +Symbol+ or +String+ # The name of this attribute. This will be assigned using "name=" for # generated instances. def add_attribute(name, &block) declaration = Declaration::Dynamic.new(name, @ignore, block) @definition.declare_attribute(declaration) end def transient(&block) proxy = DefinitionProxy.new(@definition, true) proxy.instance_eval(&block) end # Calls add_attribute using the missing method name as the name of the # attribute, so that: # # factory :user do # name { 'Billy Idol' } # end # # and: # # factory :user do # add_attribute(:name) { 'Billy Idol' } # end # # are equivalent. # # If no argument or block is given, factory_bot will first look for an # association, then for a sequence, and finally for a trait with the same # name. This means that given an "admin" trait, an "email" sequence, and an # "account" factory: # # factory :user, traits: [:admin] do # email { generate(:email) } # association :account # end # # and: # # factory :user do # admin # email # account # end # # are equivalent. def method_missing(name, *args, &block) # rubocop:disable Style/MethodMissing if args.empty? __declare_attribute__(name, block) elsif args.first.respond_to?(:has_key?) && args.first.has_key?(:factory) association(name, *args) else raise NoMethodError.new( "undefined method '#{name}' in '#{@definition.name}' factory", ) end end # Adds an attribute that will have unique values generated by a sequence with # a specified format. # # The result of: # factory :user do # sequence(:email) { |n| "person#{n}@example.com" } # end # # Is equal to: # sequence(:email) { |n| "person#{n}@example.com" } # # factory :user do # email { FactoryBot.generate(:email) } # end # # Except that no globally available sequence will be defined. def sequence(name, *args, &block) sequence = Sequence.new(name, *args, &block) FactoryBot::Internal.register_inline_sequence(sequence) add_attribute(name) { increment_sequence(sequence) } end # Adds an attribute that builds an association. The associated instance will # be built using the same build strategy as the parent instance. # # Example: # factory :user do # name 'Joey' # end # # factory :post do # association :author, factory: :user # end # # Arguments: # * name: +Symbol+ # The name of this attribute. # * options: +Hash+ # # Options: # * factory: +Symbol+ or +String+ # The name of the factory to use when building the associated instance. # If no name is given, the name of the attribute is assumed to be the # name of the factory. For example, a "user" association will by # default use the "user" factory. def association(name, *options) if block_given? raise AssociationDefinitionError.new( "Unexpected block passed to '#{name}' association "\ "in '#{@definition.name}' factory", ) else declaration = Declaration::Association.new(name, *options) @definition.declare_attribute(declaration) end end def to_create(&block) @definition.to_create(&block) end def skip_create @definition.skip_create end def factory(name, options = {}, &block) @child_factories << [name, options, block] end def trait(name, &block) @definition.define_trait(Trait.new(name, &block)) end def initialize_with(&block) @definition.define_constructor(&block) end private def __declare_attribute__(name, block) if block.nil? declaration = Declaration::Implicit.new(name, @definition, @ignore) @definition.declare_attribute(declaration) else add_attribute(name, &block) end end end end

ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]

また同じようなエラーの解決策を Qiitaで見つけたのですが該当箇所が異なり、未解決のままです。

同じような経験のある方いらっしゃいますでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

winterboum

2019/07/15 08:06

エラーの元は  undefined method 'key' in 'ae_param' factory です。 spec/factory に 問題があります。 ae_param を探してみて下さい
asm

2019/07/15 08:21

エラーログをpastebinやgistあたりにアップロードするなどの方法でよいので全文提示できますか?
Toshinori23

2019/07/15 08:47

/home/toshiki23の以下の階層でspecと検索してみたのですが、spec/factoryというディレクトリは見つかりませんでした。
Toshinori23

2019/07/15 08:48

pastebinにエラー全文表示させていただきました。
winterboum

2019/07/15 08:58

ごめ factories でした、これはありませんか?
Toshinori23

2019/07/15 10:03

ありました! FactoryBot.define do ~~ の中の属性名を{}することで解決することができました!
guest

回答1

0

ベストアンサー

エラーログを見るコツとして
まず、Tracebackの中から自分が書いた行を探し出すことです。
(ライブラリ側よりも、自分で書いたスクリプトの方が原因である事が圧倒的に多い)

今回のエラーログですと

49: from /mnt/c/pick_pro/PickGoManagerRuby/config/environment.rb:5:in `<top (required)>' 8: from /mnt/c/pick_pro/PickGoManagerRuby/spec/factories/auto_entries.rb:1:in `<top (required)>' 4: from /mnt/c/pick_pro/PickGoManagerRuby/spec/factories/auto_entries.rb:4:in `block in <top (required)>' 1: from /mnt/c/pick_pro/PickGoManagerRuby/spec/factories/auto_entries.rb:5:in `block (2 levels) in <top (required)>'

が、あなたが管理している筈の行になります。

エラーの内容から鑑みて/mnt/c/pick_pro/PickGoManagerRuby/spec/factories/auto_entries.rb:5がエラー発生行だと思います。

投稿2019/07/15 08:59

asm

総合スコア15147

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Toshinori23

2019/07/15 10:04

ズバリそこでした汗 エラー文をしっかり読もうと思います。。。 大変助かりました。ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問