Ruby on Rails Custom Classes - ruby-on-rails-3

I wrote a class in Ruby which exists in my config/com/meow location. After creating my class, I set my application.rb config.autoload_paths to the following:
config.autoload_paths += %W(#{config.root}/com/meow/)
When doing this, I received an error which stated uninitialized constant.
Thinking that I perhaps loaded the path wrong, I changed the path to the following:
config.autoload_paths += Dir["#{config.root}/com/meow/"]
After doing this, I still received the same error, 'uninitialized constant'.
My goal is to reference a public method which exists in my custom Ruby class. I want to reference this method from the ApplicationController.
Inside my ApplicationController, I have a reference to the class and the method as defined by [class].[method]
What do I need to be doing to get around this error and in order to reference the methods contained within my class from my ApplicationController?

I think you're just a bit confused about what config.root will be. config.root is the root directory of your application, that's where the usual app/, config/, db/, ... directories are. So, if you want to add config/com/meow to the auto-load paths then you'd want:
config.autoload_paths += %W(#{config.root}/config/com/meow)
I'd probably just throw your custom classes in lib/ though, then they'd be in a standard location where people would normally look and you wouldn't have to worry about customizing the auto-load paths.

Related

What is the origin of $generalUtil in my atlassian-plugin.xml?

I'm studying the code of a custom Confluence plugin, which contains an atlassian-plugin.xml file that includes references to two variables $generalUtil and $helper, but I find no definitions of them whatsoever in the entire project. They simply work and it appears to me that they are magically instantiated out of thin air.
<web-item key="configtab" name="configtab" section="system.space.tools/addons">
<label key="myplugin.space.tools.addons.tab.label" />
<link>/spaces/myplugin-config.action?spaceKey=$generalUtil.urlEncode($helper.spaceKey)</link>
</web-item>
The $generalUtil must be an instance of com.atlassian.confluence.util.GeneralUtil, which also has a method urlEncode(). But where does this variable originate from?
What puzzles me even more is the $helper, which has a spaceKey field/method that I find in the code, but without any relationship to any kind of Helper class. The $helper also appears in a velocity template, but also without any definition of it. Any ideas where this stuff is documented?
generalUtil is documented here: https://docs.atlassian.com/ConfluenceServer/javadoc/7.11.6/
I think helper is https://docs.atlassian.com/ConfluenceServer/javadoc/7.11.6/com/atlassian/confluence/themes/GlobalHelper.html
They are injected into the Velocity context used to render that link.

How do I include MTL_HEADER_SEARCH_PATHS in Swift Package Manager Package.swift?

In a internal .metal file in the ShaderPackage defined in Package.swift, I want to include an internal header. That header is nested deeply inside the include folder and I don't want to have to use the relative path. In a non Swift Package Manager (SPM) project, I can just set MTL_HEADER_SEARCH_PATHS to recursively include all subfolders, then include Header.h anywhere in the project without needing to know exactly where it is. (This isn't about exposing either file beyond the package bounds - just an internal-to-package question).
First question: Is there a way to set MTL_HEADER_SEARCH_PATHS from a Package.swift (manifest file for SPM)? Doesn't look like there's any build settings for Metal, only C, CXX, and Swift. Whatever settings I add to cSettings in the form of .headerSearchPath("include/subfolder") doesn't get picked up by Metal, nor .cXXSettings or .swiftSettings. Can I define a custom setting somehow?
Second: If there's a way to set MTL_HEADER_SEARCH_PATHS, can I do it recursively? Or do I have to add each subfolder within include? Thanks!

Yii2 "Page not found" when using CRUD generator

I have succesfully used Yii2 Model & CRUD Generators to obtain some skeleton code files for my web app. Particularly, the CRUD Generator claims to have succesfully created its view files into:
<yii_root>/basic/views/<my_view_name>/*.php
which I got by leaving "View Path" field blank.
However, browsing to:
https://<my_site_FQDN>/basic/web/index.php?r=<my_view_name>/index
spits a "Not Found (#404)" error and I'm unable to find any useful info in the Yii2 debug logs.
Any idea on this matter shall be welcome.
Antonio
<my_view_name> this is a terrible way of looking at this. Read about MVC.
You are creating controllers, routes are to controllers not to views. Stop looking if the views are there... look if the controller is there. You never interact with a view, you always do with a controller. So, is your controller there? are you sure you have created it?
Also what is the controller name? if you have something like ProductCategory then the correct route is
https://<my_site_FQDN>/basic/web/index.php?r=product-category/index
and not
https://<my_site_FQDN>/basic/web/index.php?r=ProductCategory/index
Edit
Ok, I see your problem, stop putting folders under other folders and so on. You created your CRUD wrong. Your controller has to be directly under controllers not under controllers/bibliografia, the same goes for the model. Delete the files and start again with CRUD as probably your namespaces are also wrong.
In my case, Yii2 consistenly writes the following with gii CRUD auto-generator.
namespace app\Controllers;
Notice uppercase 'C' for Controllers. This causes 404 error.
It should be :
namespace app\controllers
This fixed my 404 error.
I found with Yii2 (advanced template) that the generated controllers had:
namespace app\controllers;
I had to change this to:
namespace frontend\controllers;
I fixed it by capitalizing the first letter of the controller name.
Controller name should start with capital letters.
If lower case is used, Controller generator won't throw any error, but you will get not found(404) error in the browser.
this threw an error:
app\controllers\testController
this worked:
app\controllers\TestController
Its very Simple, change the namespace and please be careful while creating CRUD..
change namespace app\controllers; to namespace backend\controllers;

How to get a module instance in PRISM

I have a PRISM desktop app which loads modules from a directory with the help of the DirectoryModuleCatalog.
Everything is fine, except that I cannot find a way to get the instance of a loaded module.
IModuleManager and IModuleCatalog don't have a method like getInstance(ModuleInfo) or similar.
See
moduleManager.LoadModule(moduleInfo.ModuleName);
This line loads the module properly(moduleManager is of type IModuleManager), but what do I have to do next to get the actual instance of this module?
The modules are loaded on demand of the user, so I cannot register all modules at startup within the bootstrapper.
If by Module instance you mean the class that implement IModule, then you must explicitly register the instance into the container to be able to get it.
Although the aforementioned will work, you should not take that approach at all. The idea is that the module classes are specific to a particular module and should only be used for module initialization purposes.
I would place each module's Start method in a separate component (IStartable), register each component in the container with a different Id and resolve/import an IEnumerable to get all instances that have the start method.
Hope this helps

Should there be a link between the class name and the file name in which it resides?

OK, so I have 2 files (header and implementation) named MyLib.h and MyLib.m, inside those 2 files I have multiple classes, protocols and interfaces but none called 'MyLib'. Now, everything works just fine, I have only one problem, xCode doesn't show me any class hint except for MyLib (which btw is only the name of the file, there is no MyLib class).
Now, this small problem made me think about it, is this a bad practice? Is is better to have a file for each class and if yes, why?
I just created a .h file with a different name from the class inside it, and Xcode gives me the completion for the class name, not the file name. Have you #imported the header wherever you're trying to use it?