rails console list directory - ruby-on-rails-3

I am trying to load a script into Rails console. In order to load the file, I need to do something like:
load scripts/my_script.rb
# This doesn't work... gives this error:
NameError: undefined local variable or method `scripts' for main:Object
load ./scripts/my_script.rb
ArgumentError: wrong number of arguments (0 for 1)
load "./scripts/my_script.rb"
LoadError: cannot load such file -- ./scripts/my_script.rb
# I feel like supermode. Tell me whyyy?
I suspect that I start off in my base rails directory, so if Rails console's "ls" command did as the terminal did (it doesn't), it would list:
app/
config/
scripts/
Gemfile
etc
What commands can I use from within Rails console to navigate around, list the contents of the current directory, and reveal what directory Rails console is currently in?
Or if this is not possible, please spare my sanity and explain why the load command with the directory and filename (and permutations) are not working.
Extra note: I need to reload different files as I make changes to them - so starting the console passing a single filename is no good.

Do you want to do some operations on some ruby files from console?
You can use
Dir.pwd
to get current Directory, and can use other File related methods to require a file.

Related

JMeter non-GUI in Jenkins issue with Include Controller

I have two scripts in my test. A_script.jmx with the main test plan and the test fragment B_script.jmx with the module.
To include B-script into A_script.jmx I use the Include Controller with a path to the B_script.jmx
All works fine when I work in GUI locally but when I try to run it in Jenkins in non-GUI I receive an error:
Error in NonGUIDriver org.apache.jorphan.util.JMeterStopTestException:
ModuleController:Notification has no selected Controller (did you
rename some element in the path to target controller?), test was
shutdown as a consequence
As I suppose the Include Controller in the A_script.jmx cannot find my B_script.jmx file here.
Should I use some special path format in my Include Controller FileName? Both scripts are kept in one directory. I tried "B_script.jmx", "../B_script.jmx" etc
Any ideas where I'm wrong?

Laravel 403 error when displaying images from storage folder

I am unable to access files saved to the storage folder. I'm able to upload, files, save files. If I run for example the size method it gets the file size of the uploaded image but when it comes to displaying the file, I get a 403 error. I used the laravel artisan command to create the symlink, I've tried manually creating the symlink. I've checked to verify that follow symlinks is in my apache config, I can cd into it from shell the permissions are 777 (I had it 755 but in trying to figure it what is wrong I changed it to 777) ownership of the symlink and files inside are all the same user and group as every other file in the public directory.
I'm super tired so maybe I'm just missing something obvious, but I can't for the life of me figure out what is wrong. The file clearly exists, its visibility set to "public". Is there any reason why I'd be able to write the directory but not display images saved there?
Edit 1:
web
app
bootstrap
config
database
error
node_modules
public
resources
routes
stats
storage
temp
vendor
Is the basic structure, with a symlink inside public pointing at storage/app/public
the filesystems for my storage folder config is:
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
I haven't really edited anything from the basic laravel install at this point. I did read someone else having a similar problem, said their issue is they weren't allow to access direcotires outside of their document root. So they just had all uploads go to their public folder instead of using the storage folder. I do have my document root set to my public folder. Could that be a problem? (I can edit my apache file if needed)
Ok - got some sleep and this morning looked over everything and realized that when logged in as the site owner, everything looks fine, however when logged in as root it shows the link as broken. Basically artisan creates an absolute link, which /storage/app/public is fine as the site owner because its a jailkitted account whose "root" directory is the web folder. However it was actually creating a symlink to the system root, of which the normally account doesn't have access to so it was returning a 403
Basically I just made the as a relative link instead of an absolute one by removing the broken symlink laravel created and while in the public directory entering:
ln -s ../storage/app/public storage
I had the same issue, after a lot of debugging i managed to identify the actual problem that caused 403 error.
Solution is simple, in
Config/Filesystem.php
where you define your public_path and storage path, you must have same/identical public_path name and storage_path end directory name.
Example:
Incorrect:
public_path('brands') => storage_path('storage/app/public/brandimages');
This will generate 403 error, "since public_path('brands')" is not same as "storage_path('../../../brandsimage')".
Correct:
public_path('brands') => storage_path('storage/app/public/brands');
Now the public_path('brands') and "storage_path('../../../brands')" are same, therefore, correct symlinks will generated,thus solving 403 error.
Generate symlinks with following artisan command
php artisan storage:link
if relative links need to be generated, than use following command
php artisan storage:link --relative
My hosting is a clud server, and my site path is /httpdocs
The solution worked for me, was:
from folder /httpdocs/public, execute ln -s ../storage/app/public storage
then everything works fine.

Elm Make starts Windows Script Host and gives error?

I'm playing in Elm, and whenever I use elm make I get an error from Windows Script Host:
The error states that there is an error in the build elm.js file. And when I look at the given line, it's the following:
return {
keys: keys, // A hash of key name to index
free: free, // An array of unkeyed item indices
} // line 10547
So I'm guessing it's bitching about the unneeded , on line 10546: free: free,.
But now my question is, why is Windows Script Host doing stuff with my build elm.js file anyway, and how can I fix it?
I already tried disabling Windows Script Host, but then I just get an error stating that it doesn't allow script to be run.
Since you have a file in that directory called elm.js, the Windows Command Line tries executing that when you type elm make. It thinks you are intending this: elm.js make.
You can get around this in a few ways:
Change the name of the output file from elm.js to something else
Move the generated elm.js file to a subdirectory
Run elm-make from the command line instead of elm make
Use another shell like Powershell, Git Bash, or Cygwin

I can't generate a model either migration in rails

I have a rails project and i want to add a new table and also make changes in one table which is already in the project.
From the terminal and inside the folder of the existing rails project I write this:
Mini-1:arbinet anna$ rails generate model PriceRate profitable_routes_id:int normalized_rate:float normalized_payout:float margin:float old_rate:float old_payout:float old_margin:float
And also this for the migration:
Mini-1:arbinet anna$ rails generate migration ChangeColumnsFromProfitableRoutes
But for both I get this message:
Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/anna/.rvm/rubies/ruby-1.9.3-p286/bin/ruby
-b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL)
-m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL)
[--skip-gemfile] # Don't create a Gemfile
[--skip-bundle] # Don't run bundle install
-G, [--skip-git] # Skip Git ignores and keeps
-O, [--skip-active-record] # Skip Active Record files
-S, [--skip-sprockets] # Skip Sprockets files
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript] # Skip JavaScript files
[--dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit] # Skip Test::Unit files
[--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend] # Run but do not make any changes
-q, [--quiet] # Suppress status output
-s, [--skip] # Skip files that already exist
Rails options:
-h, [--help] # Show this help message and quit
-v, [--version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.
And I don't have any clue why, but it was working when I create the other tables.
You should call the 'rails' command from within the proper docroot (folder) of your app.
So if your app lives in /pub/www/mycoolapp/ you should do: cd /pub/www/mycoolapp/ and run the rails commands from there
A little bin later, but maybe it is a problem that any of you may have.
Run this command inside your app root folder
bundle exec rake rails:update:bin
And enjoy coding!!

How do I install this service_wrapper for mongrel/rails on my windows server?

I have been given the unpleasant task of installing a Rails 3 app I have written on Windows Server 2008 (definitely not my choice - was promised a linux server but I.T. pulled the rug out at the last minute so please don't suggest a change in environment as a solution).
I followed the instructions on this blog post (with a few minor modifications) and now actually have my app up and running under Windows/IIS (proxying mongrel) after a great deal of frustration. The only thing remaining is to get mongrel running as a service.
Unfortunately the mongrel gem has not been kept up-to-date for Rails 3 and while I can get the app running under mongrel at the command line I am unable to use mongrel_service to get the app running as a service.
The solution to this appears to be to use the service_wrapper project on github which has been mentioned in this previous question. The project is not yet complete but apparently functional but comes without documentation/binaries. I have looked through the source-code and don't really understand what is it/how it works so was wondering if someone can point me in the right direction (or, even better, walk me through how) to get this installed.
So close, yet still so far.....
Alright I have this worked out (with a little help from luislavena himself - thanks).
Download service_wrapper-0.1.0-win32.zip from https://github.com/luislavena/service_wrapper/downloads and extract service_wrapper.exe from bin/. I extracted it to C:\service_wrapper.
Next set up a configuration file. I used the hello example and modified it for my app then placed it in the C:\service_wrapper directory.
; Service section, it will be the only section read by service_wrapper
[service]
; Provide full path to executable to avoid issues when executable path was not
; added to system PATH.
executable = C:\Ruby192\bin\ruby.exe
; Provide there the arguments you will pass to executable from the command line
arguments = C:\railsapp\script\rails s -e production
; Which directory will be used when invoking executable.
; Provide a full path to the directory (not to a file)
directory = C:\railsapp
; Optionally specify a logfile where both STDOUT and STDERR of executable will
; be redirected.
; Please note that full path is also required.
logfile = C:\railsapp\log\service_wrapper.log
Now just create the service with
sc create railsapp binPath= "C:\service_wrapper\service_wrapper.exe C:\service_wrapper\service_wrapper.conf" start= auto
(watch for the spaces after binPath= and start=. It won't work without them)
Then start it with
net start railsapp
And you're home and hosed!
I ought to contribute due to this article. For config of using bundle exec, use the following:
Note that I am setting up rubyCAS! it's a great OpenCAS authentication mechanism!!!
; Service section, it will be the only section read by service_wrapper
[service]
; Provide full path to executable to avoid issues when executable path was not
; added to system PATH.
executable = C:\Ruby\bin\ruby.exe
; Provide there the arguments you will pass to executable from the command line
arguments = D:\rubycas-server bundle exec rackup -s mongrel -p 11011
; Which directory will be used when invoking executable.
; Provide a full path to the directory (not to a file)
directory = D:\rubycas-server
; Optionally specify a logfile where both STDOUT and STDERR of executable will
; be redirected.
; Please note that full path is also required.
logfile = D:\rubycas-server\log\service_wrapper.log