Rails runner does not find file, Rails version 5.1.3 - ruby-on-rails

I have a regular Rails project that is up and running fine, using Rails 5.1.3.
I recently discovered Rails runner and tried it along the documentation (https://guides.rubyonrails.org/command_line.html#rails-runner).
However, my Rails runner seems to be incapable of coping with files. I have a file lib/manual_exports/my_export.rb, and it really exists. I tried running
rails runner lib/manual_exports/my_export.rb
and
rails runner ./lib/manual_exports/my_export.rb
I always get the response
Please specify a valid ruby command or the path of a script to run.
Run 'bin/rails runner -h' for help.
undefined local variable or method `lib' for #<Rails::Command::RunnerCommand:0x00007fb13008b310>
# (or `.' instead of `lib')
This sounds as if runner thought my path was a Ruby command, which shouldn't be the case.
When I try reading in the file directly like
rails runner "eval(File.read 'lib/manual_exports/my_export.rb')"
or
rails runner "eval(File.read '#{Rails.root}/lib/manual_exports/my_export.rb')"
I get no answer at all, until I press ctrl+C, which gives me the stack trace
/Users/marion/.rvm/gems/ruby-2.4.2/gems/railties-5.1.3/lib/rails/commands/runner/runner_command.rb:37:in `read': No such file or directory # rb_sysopen - lib/manual_exports/my_export.rb (Errno::ENOENT)
I tried running a command directly (rails runner 'puts "hi"'), which worked. However, it took incredibly long - about two seconds. Can anybody explain to me what is happening here? Thank you!

Related

why rails server is not working on windows 10

I have created the new rails project and trying to run it without doing any changes. I am using the power shell in windows 10. When I am running the rails s command its not starting the server. Please see attached image. I have highlighted the installed ruby version.
The error is there in the output, you do not have a rails app to start a server for, you can create a new app with:
rails new <name-for-your-app>
Follow along this tutorial
to help you get started with rails.
I think this command will work or you are missing something which is required to run rails server
bin/rails server
I've got similar error when I am not in rails project directory. Seems you are out of directory.
Please run those full commands in powershell
cd c:/
rails new testapp
cd testapp
rails s

How to run rails server - execute wkhtmltopdf - stop rails server

I've been long time investigating how to generate complex .pdf files (many images and 30 pages aprox). from a html web, of my rails application.
At the end I realized than the best option is wkhtmltopdf from command line.
using pdfKit gem don't work in production, but it works in development
using wkhtmltopdf from command line, works in development but neither in production.
I have read a lot of issues with wkhtmltopdf, so I abandon use wkhtmltopdf getting info from production web server. --> Instead I have created a new environment "genera_pdf" to run in production database, with development configuration (assets, cache..etc)
And now I need to run some proces than execute this:
1) RAILS_ENV=genera_pdf rails s
2) wkhtmltopdf localhost:3000 result.pdf
3) stops (CTRL+C) rails s
If this is achievable, Whats the best way to do this in Linux?
I'm absolutly missed...with rake tasks? or rails runner? or Cron-task?
Thanks a lot

Running Webrick in Windows - Help getting started with Rails

I'm new to Ruby on Rails (and programming!) and am running through the guide here...
http://guides.rubyonrails.org/getting_started.html
However I am stumped on step 4.1. Creating a webserver as Webrick does not seem to run at all. Here is the error message that I see...
F:/Documents/Google Drive/Development/Ruby21/lib/ruby/gems/2.1.0/gems/railties-4
.2.0/lib/rails/app_rails_loader.rb:39:in `exec': No such file or directory - "F:
/Documents/Google Drive/Development/Ruby21/bin/ruby.exe" (Errno::ENOENT)
The Ruby.exe does indeed exist in this location, all previous steps have been fine up until now. Any help would be much appreciated!
Is Ruby and Rails installed locally or is it in an external flash drive or cloud storage? You might need to reinstall everything into your C:\ drive to run a local server.
Also, did you copy the command from the guide verbatim? If you're running windows and using a cmd prompt, you don't need to include the "bin/" part of that command. Simply enter "rails server" or "rails s" for short to start the server.

Rails 4.0 receiving emails - no such file (runner)

Up until now I've been using script/runner to forward bouncebacks to eblast-bounceback#mydomain.com and eblast-bounceback#dev.mydomain.com. However it is no longer working in Rails 4.0. I also can't seem to find a good resource online to illustrate how to do it. I usually get directed to the 'whenever' gem - but that's for cron jobs, not for 'piping to programs'.
So this is essentially what I'm currently doing, but is failing:
|/home/user/rails/dev.www/script/rails runner 'EBlast.receive(STDIN.read)' -e development
How do I get this to work? I'm not on Rails 4.1, I'm on 4.0. FWIW I do not have bin/rails. The above command yields "no such file or directory".
There were actually a few things I needed to do.
The email eblast-bounce#dev.mydomain.com was considered 'unroutable'. At first I figured it was because there wasn't any MX records for the subdomain, so I added one. But then I still got the error. I had manually updated the aliases file in /etc/valiases to pipe to the program using a symlinked directory (because I was deploying with Capistrano, and the directory ends up changing after every deploy). Turns out symlinks don't work for some reason when it comes to exim routing (/home/me/rails_deployments/dev.www/current/bin/rails fails). Maybe I'm wrong about the symlinks thing but the problem went away when I used the solution below.
This problem however was solved when I eventually came to another problem (/usr/bin/env: ruby: No such file or directory). I'm using RVM to manage rubies/gems, and apparently the email forwarder didn't know what ruby was. This leads to the final solution:
(when in cPanel, "pipe to program" assumes the user home directory (/home/me/))
.rvm/wrappers/ruby-2.1.0#website/ruby /home/me/rails_deployments/dev.www/current/bin/rails runner 'EBlast.receive(STDIN.read)' -e development
Where ruby-2.1.0 is my current ruby version, and #website is the gemset used by the EBlast.receive code base.
EDIT: Spoke too soon, the command has its own set of problems...(gemfile not present). This is ludicrous.

cannot run rails server command for already created project

I have got an application which was zipped and I unzipped the files and it gave me a folder with all the required structure of a rails application. But when I am going inside the directory and running the rails server command, its not doing anything, but showing me the list of options rails command can do. What would have been the problem?
thanks
Maybe this will help from app folder try:
ruby script/rails server
As explained by Dave Isaacs, Showing the list of options is what the rails command does when it is executed outside the context of an application (i.e., not in the application directories).
Type the full command, including the /script path to the CLI.
script/rails server
instead of
rails server
where script is the path to the rails command that, in a Rails 3 application, lives in the script folder.
I would assume that the application you got was written with rails 2.x. In that case, you have to start it with
script/server

Resources