添加到自动加载路径但未加载

时间:2018-06-15 23:59:57

标签: ruby-on-rails ruby

我在AWS EC2 t2.micro上使用Rails 5.1.6。

我有一个文件,比如说import {createAction, handleActions} from 'redux-actions'; import { Map, List } from 'immutable'; // firestore import * as db from '../../shared'; // Action types const GET_NAME = 'categoryImgList/GET_NAME'; // action creator export const getName = createAction(GET_NAME, () => { db.getCategoryNames().then(data => { const arr = []; data.forEach(doc => { console.log(doc.data().name); arr.push(doc.data().name); }); console.log('arr'); console.log(arr); }) }); // none const initialState = Map({ name: List() }); // Reducer export default handleActions({ [GET_NAME]: (state, { payload: name }) => { console.log(state); console.log({name}); const item = Map({ name }); return state.update('name', name => name.push(item)); } }, initialState); ,其中的是

lib/foo/bar.rb

已定义。我添加了

class Foo::Bar
end

config.autoload_paths += %W(#{config.root}/lib) ,但当我检查从config/application.rb加载常量Foo::Bar时,会引发rails console名称错误。

所以,我添加了行

uninitialized constant Foo::Bar

puts "CONFIG ROOT IS #{config.root};" puts "AUTOLOAD PATHS ARE #{config.autoload_paths};" 的末尾,以查看它们是否设置正确,并且它们是正确的。

然后,我在config/application.rb中尝试了require './lib/foo/bar.rb'; Foo::Bar,也没关系。

(本地)码头工人的尝试也很好。

有什么问题?为什么rails console中的常量未加载?

1 个答案:

答案 0 :(得分:1)

你试过了吗?

module Foo
  class Bar
  end
end

https://dan.chak.org/enterprise-rails/chapter-3-organizing-with-modules/

相关问题