cleanup / organise the /config/initializers folder for new rails 4 project - ruby-on-rails

Migrating from a rails 3 project and found that I have to many initialisers for my taste,
trying to clean out the config folder and minimise the use of initialisers or better organise them.
Currently I have:
...
-rw-r--r-- 1 Me staff 81 Jun 22 14:54 simple_navigation.rb
-rw-r--r-- 1 Me staff 1535 Jun 22 14:54 simple_navigation_overrule.rb
-rw-r--r-- 1 Me staff 27 Jun 22 14:54 will_paginate.rb
-rw-r--r-- 1 Me staff 514 Sep 10 23:12 wrap_parameters.rb
Are there ways to clean this up a bit or use subfolders to organise this better? I feel there are several initialisers im not sure still needed like the fix_ssl.rb one and some other initialisers that only have a 1 line.
Preferrable I would like to clean this up more

It looks like you can create whatever subdirectories you need.
From the guide for using initializer files:
You can use subfolders to organize your initializers if you like,
because Rails will look into the whole file hierarchy from the
initializers folder on down.

Related

Docker can't find bind source path for entrypoint script, even though file exists

I'm trying to build a service (Google Cloud Composer, which is basically just Airflow) locally via Docker. However, I'm getting the following error message:
│ http+docker://localhost/v1.41/containers/create?name=composer-local-dev-gcp_composer_locally: Bad Request ("invalid mount │
│ config for type "bind": bind source path does not exist: │
│ /opt/homebrew/lib/python3.10/site-packages/composer_local_dev/docker_files/entrypoint.sh")
However, such a file does exist and is executable:
16777233 2895095 -rwxr-xr-x 1 <my_unix_name> admin 0 1281 "Feb 13 14:26:24 2023" "Feb 13 14:26:24 2023" "Feb 13 14:26:24 2023" "Feb 10 17:04:20 2023" 4096 8 0 /opt/homebrew/lib/python3.10/site-packages/composer_local_dev/docker_files/entrypoint.sh
I've confirmed my user is a member of the "admin" group, so I don't think this is a file permissions error.
How can I get Docker to recognize this entrypoint and run the relevant script?

electron: Failed to load URL: http://localhost:3000/main_window with error: ERR_CONNECTION_REFUSED in production mode

With the executable (yarn make) I get this error :
electron: Failed to load URL: http://localhost:3000/main_window with error:
ERR_CONNECTION_REFUSED
This error does not show up in the development mode
I tried to differentiate between dev and prod modes in main :
import isDev from 'electron-is-dev'
const createWindow = (): void => {
// Create the browser window.
const mainWindow = new BrowserWindow({
height: 600,
width: 800,
webPreferences: {
preload: MAIN_WINDOW_PRELOAD_WEBPACK_ENTRY
}
});
// and load the index.html of the app.
isDev ? mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY) : `file://${path.join(__dirname, '../build/index.html')}`
// Open the DevTools.
if (isDev ) {
mainWindow.webContents.openDevTools();
}
};
but in this way the error message doesn't show up, but also the correct window's page Electron App doesn't show up :
In Development Mode : "Got Finally!!" message in the window's page is present,
but not in Production Mode
meaning that the page is not correctly loaded
Other Info:
Electron: 19
O.S. : Ubuntu 22.04
How to make it work?
Update 1)
Thanks to #Bets comment I realized I made two mistakes (the folder and the ternary operator) and I updated the line of code accordingly:
mainWindow.loadURL(isDev ? MAIN_WINDOW_WEBPACK_ENTRY : `file://${path.join(__dirname, '../renderer/main_window/index.html')}`)
The folder this time is correct:
console.log(path.join(__dirname,'../renderer/main_window/index.html')) =>
/home/raphy/ForgeTypescriptReactWebpack
/out/forgetypescriptreactwebpack-linux-x64/resources/app/.webpack
/renderer/main_window/index.html
raphy#raohy:~/ForgeTypescriptReactWebpack/out/forgetypescriptreactwebpack-linux-x64/resources/app/.webpack/renderer/main_window$ ls -lah
total 3,5M
drwxrwxr-x 2 raphy raphy 4,0K gen 4 12:17 .
drwxrwxr-x 3 raphy raphy 4,0K gen 4 12:17 ..
-rw-rw-r-- 1 raphy raphy 386 gen 4 12:17 index.html
-rw-rw-r-- 1 raphy raphy 3,4M gen 4 12:17 index.js
-rw-rw-r-- 1 raphy raphy 1,8K gen 4 12:17 preload.js
but, still, the page is not correctly loaded and not getting the right output
It looks like your code for loading the page is causing the issue, it should be:
// and load the index.html of the app.
mainWindow.loadURL(isDev ? MAIN_WINDOW_WEBPACK_ENTRY : `file://${path.join(__dirname, '../build/index.html')}`)
That is, the ternary operator should determine what path/URL to load as the argument for the mainWindow.loadURL function call.
Thanks to electron-forge people, who answered my help-request in Discord, I solved the issue with these two steps:
I upgraded all #electron-forge/* dependencies to latest
in main : mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY)

Liquibase "Cannot find the declaration of element 'databaseChangeLog'" in xml changeLog file

Following This guide from Liquibase's official website I've created my own changelog-master.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="https://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<includeAll path="/home/username/liquibase/examples/sqlite-test" filter="sql"/>
</databaseChangeLog>
I've then created the liquibase.properties file in the same folder:
# Enter the path for your changelog file.
changeLogFile=changelog-master.xml
#### Enter the Target database 'url' information ####
url=jdbc:sqlite://home/username/liquibase/examples/sqlite-test/testdb
Which is correct because if I run a normal .sql changelog it runs correctly and updates my DB.
I've then created a changelog file in sql which has to be automatically executed when launching liquibase update which is 000020-changelog.sql
--liquibase formatted sql
--changeset daniel:3
create table phonebook(name TEXT, surname TEXT, type TEXT, phone_number TEXT);
But when I go and launch liquibase update I get an error from the XML parser:
Unexpected error running Liquibase: cvc-elt.1.a: Cannot find the declaration of element 'databaseChangeLog'.
And I can't understand what the problem is. I've checked multiple times if the changelog-master.xml file is correct and it looks like it is. And from what I can find the cvc-elt.1.a is an XML Parsing error, like databaseChangeLog it's not declared in the xml schema.
I'm doing this so that in the future I can create as many changelogs as I want and have them executed one after the other automatically.
I've been looking for some solutions for this problem but I can't find anything. I've found a link to the official forums but it's now a dead link.
Extra info:
Liquibase version 4.0.0
Installed JRE: openjdk 11.0.8 2020-07-14
OS: Debian 10
SQLite version 3.27.2
08/09/2020 edit:
as asked in the comments this is the project's structure:
root#dev-machine:/home/username/liquibase/examples/sqlite-test# ls -la
total 68
drwxr-xr-x 2 root root 4096 Sep 4 17:28 .
drwxr-xr-x 5 username username 4096 Sep 4 17:02 ..
-rw-r--r-- 1 root root 139 Sep 4 13:35 000020-changelog.sql
-rw-r--r-- 1 root root 118 Sep 4 13:36 000030-changelog.sql
-rw-r--r-- 1 root root 201 Sep 4 17:05 000040-changelog.sql
-rw-r--r-- 1 root root 240 Sep 4 17:28 000050-changelog.sql
-rw-r--r-- 1 root root 456 Sep 4 14:22 changelog-master.xml
-rw-r--r-- 1 root root 2637 Sep 4 16:36 liquibase.properties
-rw-r--r-- 1 root root 32768 Sep 4 17:28 testdb
testdb is the sqlite database I'm using to test liquibase. The .sql files are the consecutive changelogs that must be run to update the DB
What was causing the issue I was having was the fact that in my changelog-master.xml I had an outdated XSD version, which was causing something to break into the XML Parser. To fix it I've changed it with the following:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.0.xsd
">
<includeAll path="schema/"/>
</databaseChangeLog>
and moved all my *.sql files into the schema/ folder. Other than that I've renamed all my .sql files using the *.databasetype.sql namescheme, in my case 000020-changelog.sqlite.sql. Had to do this because otherwise the files that used --liquibase formatted sql wouldn't be executed.
For me, this issue is more related to http and https. The following shows the successful config:
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" <-- NOT HTTPS!
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <-- NOT HTTPS!
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog <-- NOT HTTPS!
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.4.xsd">
<includeAll path="changelogs/" relativeToChangelogFile="true"/>
</databaseChangeLog>
If http in any one of the three line is changed to https, it will throw the exception:
liquibase.exception.ChangeLogParseException: Error parsing line 6 column 70
of classpath:db/main.xml: cvc-elt.1.a: Cannot find the declaration of
element 'databaseChangeLog'.

Print load time per file when start a Rails 2 project

How can I print for each file how long is it taking.
I am thinking about monkey patching load or some load method in Rails, but I don't know a lot about Rails 2 inner things.
I would expect this kind of output:
config/environment.rb ---> 60 s
config/development.rb ---> 30 s
config/initializers/some.rb ---> 20 s
Any starting point is really appreciated.
Update
I am measuring time with:
from = Time.now; p from.to_s + '----- env.rb'
to = Time.now - from; p "env.rb ---" + to.to_s
Changing env.rb to boot.rb in boot.rb file, these are my results:
"Thu Feb 13 18:54:17 +0000 2014----- boot.rb"
"boot.rb ---0.001493"
"boot.rb ---0.941835"
Loading development environment (Rails 2.3.18)
"Thu Feb 13 18:54:19 +0000 2014----- env.rb"
"env.rb ---0.001378"
"Thu Feb 13 18:54:19 +0000 2014----- boot.rb"
"boot.rb ---0.001712"
"boot.rb ---0.02536"
"env.rb ---67.272745"
"env.rb ---70.847089"
I am not sure why I am getting that config/boot is being called twice. From what I see most of the time is spent in environment.rb, but I removed code and time remains the same, so it should be related with other thing.
This other thing is not bundling gems, since I have:
from = Time.now; p from.to_s + '----- env.rb'
# Be sure to restart your web server when you modify this file.
#
#
require 'rubygems'
require "bundler"
Bundler.setup
to = Time.now - from; p "env.rb ---" + to.to_s
And this is printing:
"env.rb ---0.001378"
Turned out that most of the time was spent in loading files, I started a new Rails 2.3 project with part of the models of the bigger app, and time reduced from more than a minute to about 5 seconds.

grails emacs mode - "Cannot open load file" "project-mode"

I am trying to use emacs for grails development. Tried on grails-emacs-mode
There are emacs and emacs23 on my ubuntu 12.04.
prayag#prayag:~$ ls -l /usr/share/emacs[tab][tab]
emacs/ emacs23/
As the grails-emacs-mode suggests, I copied grails-mode.el and primary.org files to my emacs23/site-list
prayag#prayag:~$ ls -l /usr/share/emacs23/site-lisp/
total 32
-rw-r--r-- 1 root root 3013 Nov 17 00:39 debian-startup.elc
drwxr-xr-x 2 root root 4096 Nov 17 00:39 dictionaries-common
-rw-r--r-- 1 root root 18205 Feb 14 01:11 grails-mode.el
-rw-r--r-- 1 root root 0 Feb 14 01:11 primary.org
-rw-r--r-- 1 root root 106 Sep 22 01:16 subdirs.el
Then, created init.el inside .emacs.d as there exists no .emacs file in home directory. The init.el conatains
(require 'grails-mode)
(setq grails-mode t)
(setq project-mode t)
(add-to-list 'auto-mode-alist '("\.gsp$" . nxml-mode)) ; Use whatever mode you want for views.
(project-load-all) ; Loads all saved projects. Recommended, but not required.
now, opening emacs23 doesn't show any grails in the menubar.
I also tried
M-x
load-file .emacs.d/init.el
which throws
Warning (initialization): An error occurred while loading `/home/prayag/.emacs.d/init.el':
File error: Cannot open load file, project-mode
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.
On starting emacs23 --debug-init, following error is thrown.
Debugger entered--Lisp error: (file-error "Cannot open load file" "project-mode")
require(project-mode)
eval-buffer(#<buffer *load*<2>> nil "/usr/share/emacs/23.3/site-lisp/grails-mode.el" nil t) ; Reading at buffer position 422
load-with-code-conversion("/usr/share/emacs/23.3/site-lisp/grails-mode.el" "/usr/share/emacs/23.3/site-lisp/grails-mode.el" nil t)
require(grails-mode)
eval-buffer(#<buffer *load*> nil "/home/prayag/.emacs.d/init.el" nil t) ; Reading at buffer position 23
load-with-code-conversion("/home/prayag/.emacs.d/init.el" "/home/prayag/.emacs.d/init.el" t t)
load("/home/prayag/.emacs.d/init" t t)
#[nil "\205\264
grails-mode requires project-mode as mentioned on the emacs-grails-mode page. So, you'll also need to install project-mode.
Also grab the remaining groovy packages(all but grails-mode) from here.
emacs-grails-mode-ext is a modest contribution to grails-mode allowing you to run Grails commands directly from emacs. For a given project(project-mode), you can run Grails commands such as create-domain-class, create-service, etc.
I also use the function ido-find-file-in-tag-files from here, I bind it to C-x C-M-f .
Simple guide with emacs-grails-mode:
Create a project from the command line or eshell -> grails create-app yourapp
Using dired, go to your Grails project folder
M-x project-new -> to create a new project(project-mode)
M-x project-save -> Save the project
M-x project-load-and-select -> Your project-name as argument
There's also a Grails menu if you use the menubar
You could also use my current emacs setup here, if you have emacs24 installed. I believe that it's available for Ubuntu 12.04, but I'm not sure. I usually build emacs from source on OSX or I use emacs-snapshot in Ubuntu.
Hope this helps.
I don't know Grail-mode at all. I've just clicked your link, and they state that project-mode is a dependency:
Dependencies:
project-mode is the only dependency.
As a consequence you will also have to install it. Link to the Emacs project code.
I am hoping for you this project does not have additional dependencies...
As a side note: later, try to install the last emacs (v24) which embeds a very convenient way to deal with package installation and dealing with packages dependencies. I've just check it out, it is present on an alternative (but very know) repository: Marmalade-repo.org.

Resources