Getting error uninitialized constant NHLSDecorator if config.eager_load = false - ruby-on-rails-4

I am new to Rails and working on Rails 4 application. In my development.rb I have
config.cache_classes = false
config.eager_load = false
Here is the directory structure of my application
Here is the snippet of my NHLSDecorator class
Here is the line from the _results_html.erb file that when run raise error
<% posting = Posting::Decorator.new(posting) %>
Now with this I am getting error that
I also have nhls/app/presenters directory in my autopath. I also added app/presenters/posting directory. Here is the snapshot of my application.rb file
# Custom directories with classes and modules you want to be autoloadable.
config.autoload_paths += %W(#{config.root}/extras)
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.autoload_paths += Dir["#{config.root}/app/controllers/**/"]
config.autoload_paths += Dir["#{config.root}/app/reports/**/"]
config.autoload_paths += Dir["#{config.root}/app/searchers/**/"]
config.autoload_paths += Dir["#{config.root}/app/workers/**/"]
config.autoload_paths += %W(#{config.root}/app/models/ckeditor)
config.autoload_paths += %W(#{config.root}/app/presenters/posting)
But I am getting the error. If I change config.eager_load = true. Then it works fine. Why I am getting this error? What can be the cause?
Thanks

I solved it. Basically what I did I rename the file in app/presenters directory to nhls_decorator.rb. Instead of NHLS_Decorator. Also in the code I changed the lines
class Posting::Decorator < NhlsDecorator
note previously it was class Posting::Decorator < NHLSDecorator. And also in the file nhls_decorator.rb
class NhlsDecorator < SimpleDelegator
note previously it was class NHLSDecorator < SimpleDelegator.
So renaming did the trick. Actually with debug I found that for NHLSDecorator filename rails unable to find any path. But when I changed it to NhlsDecorator then rails find the path which is app/presenters/nhls_decorator.rb" and loads the file.
Thanks

Related

Bitbake does not include my recipe in build

I am trying to do something straightforward: add a new layer and a new recipe. I used the
bitbake-layers create-layer
command to create the layer, and added the layer directory path to BBLAYERS variable in BUILDDIR/conf/bblayers.conf.
layer.conf
BBPATH .= ":${LAYERDIR}"
BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
${LAYERDIR}/recipes-*/*/*.bbappend"
BBFILE_COLLECTIONS += "myname-mytest"
BBFILE_PATTERN_myname-mytest = "^${LAYERDIR}/"
BBFILE_PRIORITY_myname-mytest = "6"
LAYERVERSION_myname-mytest = "1"
LAYERSERIES_COMPAT_myname-mytest = "sumo"
Added this in local.conf:
local.conf
IMAGE_INSTALL_APPEND = " mytest-app"
bitbake-layers show-recipes
shows my layer and recipe.
mytest-app:
meta-myname-mytest 1.0
Errors in my recipe are caught in the bitbake build, but without any error, no output is produced under WORKDIR/image or logs are produced under WORKDIR/temp!
Have done this on other platforms, and can't for the life of me tell what I am doing wrong. Thanks for any help!!
It's IMAGE_INSTALL_append, not IMAGE_INSTALL_APPEND. c.f. https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-metadata.html#appending-and-prepending-override-style-syntax
For the new yocto version, you need to use
IMAGE_INSTALL:append
instead of
IMAGE_INSTALL_append
and you will be OK

How to make Qt Plugin project inside a Qt App project

When I run my application, QtCreator always show an error like this
QQmlApplicationEngine failed to load component
qrc:/main.qml:3 module "SampleModules" is not installed
I tried
- search for solutions everywhere
- move qmldir file to application project or binary folder
- change plugin
- update .pro file with many ways (even add link to resource file of plugins)
My full source code is in here, I put it to github for everyone to have a whole view of my code, it just a quick sample.
https://github.com/chaunnt/QtWithQMLPluginProjects
Here some details
My project.pro
TEMPLATE = subdirs
SUBDIRS += \
SampleModules \
SampleApp
SampleApp.depends = SampleModules
My module.pro
TEMPLATE = lib
TARGET = SampleModules
QT += qml quick
CONFIG += plugin c++11
TARGET = $$qtLibraryTarget($$TARGET)
uri = SampleModules
version = 1.0
# Input
SOURCES += samplemodules_plugin.cpp samplemodules.cpp
HEADERS += samplemodules_plugin.h samplemodules.h
DISTFILES = qmldir
!equals(_PRO_FILE_PWD_, $$OUT_PWD) {
copy_qmldir.target = $$OUT_PWD/qmldir
copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir
copy_qmldir.commands = $(COPY_FILE) "$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)" "$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)"
QMAKE_EXTRA_TARGETS += copy_qmldir
PRE_TARGETDEPS += $$copy_qmldir.target
}
qmldir.files = qmldir
unix {
installPath = $$[QT_INSTALL_QML]/$$replace(uri, \., /)
qmldir.path = $$installPath
target.path = $$installPath
INSTALLS += target qmldir
}
my app.pro
QT += quick
CONFIG += c++11
SOURCES += \
main.cpp
RESOURCES += qml.qrc
QML_IMPORT_PATH =
QML_DESIGNER_IMPORT_PATH =
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
I expect to make a Qt Plugin project which can register C++, QML, Singleton QML for my Qt App project.
my qmldir file
module SampleModules
plugin SampleModules
classname SampleModulesPlugin
typeinfo plugins.qmltypes
I fixed it myself.
add this line to main.cpp
engine.addImportPath("..");
Root cause is because the SampleApp binary can not find the folder of QML in output directory.
It is searching for folder
"Output/SampleApp/SampleModule"
but we are outputing projects as
"Output/SampleApp"
"Output/SampleModule"
NOTE: add env variable QML_IMPORT_TRACE = 1 in Build & Run environments variables in QtCreator to get which plugins is loaded and what is wrong.
I also push the fixed patch on my github for template project

Using module in lib folder in tests

I have this module in my lib folder:
module Exceptions
class NotAuthorized < StandardError
end
end
Then, I have a test for a controller like this:
class Admin::ApplicationControllerTest < ActionController::TestCase
test "should not be authorized" do
assert_raise(Exceptions::NotAuthorized) {
get :index
}
end
end
I also try to put this line on my environments/test.rb
config.autoload_paths +=%W(#{config.root}/lib)
But, when I run the test I always get:
NameError: unitialized constant Admin::ApplicationControllerTest::Exceptions
How to include the module Exceptions in the test?
Moving
config.autoload_paths +=%W(#{config.root}/lib)
to application.rb fix it.

rails 4: put models in subdirectories but without namespacing ( only to organise )

What would be the way to do this in rails 4?
For Rails 3 this works:
config.autoload_paths += Dir[ Rails.root.join('app', 'models', '**/') ]
But in Rails 4 it fails complaining about namespacing non existent ( like
app/models/users/credits.rb gives error
Unable to autoload constant User::Credits, expected
I just ran into this problem and fixed it by adding this to application.rb.
config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**}')]

EXTRA_DIST for Makefile.am repeats the directory name

I'm using EXTRA_DIST within a Makefile.am to copy some folders:
EXTRA_DIST = input/
The problem is that it repeats the directory name input/input/
Do you know any solution for this problem? is this a bug of automake?
I have found the solution. With: "EXTRA_DIST = input" instead of "EXTRA_DIST = input/" works fine