Unable to generate rails footnote - ruby-on-rails

I am trying to install debug tool called rails-footnotes on Rails 3.0 following instruction on GitHub. A check running bundle show rails-footnotes show that I got rails-footnotes-3.7.4 installed. However, when I run
rails generate rails_footnotese:install
>>Could not find generator rails_footnotese:install.
I hope someone experienced the same issue might help me out.
Thank you.

Version 3.7.4 doesn't use a generator, only the newer 3.7.5 (which hasn't been released yet) does. Also, the README has a typo; it should be rails_footnotes:install, not rails_footnotese:install (there is already a pull request to fix this).
If you want to stay on the stable 3.7.4, all the generator command does is add the config/initializers/rails_footnotes.rb file with the same content from the README:
if defined?(Footnotes) && Rails.env.development?
Footnotes.run! # first of all
# ... other init code
end
and a .rails_footnotes file with this:
#this code temporarily disables notes for all controllers
# Footnotes::Filter.notes = []
Otherwise, use the git version to make the generator work:
gem 'rails-footnotes', :git => "git://github.com/josevalim/rails-footnotes.git"

Related

Ruby on Rails - Rtesseract not working on Heroku

I am trying to deploy on Heroku RTesseract feature to read text on image.
I add the gem into the Gemfile
gem 'rtesseract'
I implemented the feature into the PagesController#home (sure it is dirty but it is for testing before adding to my real app)
class PagesController < ApplicationController
def home
image = RTesseract.new('https://www.drillster.com/info/img/screenshot-ticket-received.en.png')
#result = image.to_s
end
end
It is working well on http://localhost:3000/. I can see the text printing of the page
When I deploy on Heroku, I have add the following buildpacks :
heroku buildpacks:set heroku/ruby
heroku buildpacks:add https://github.com/pathwaysmedical/heroku-buildpack-tesseract
When I start my application on Heroku, I can see the error :
Tesseract::Error (Cannot open input file:
https://www.drillster.com/info/img/screenshot-ticket-received.en.png)
The error is raising when the code executed the line #result = image.to_s
If someone has already solve this issue, it will be really nice to help me !
Thanks in advance for your help & reading !
So it looks like they added libcurl to get images from URLS in this commit here:
https://github.com/tesseract-ocr/tesseract/commit/286d8275c783062057d09bb8e5e6607a8917abd9
That was in OCT 2019
Looking in the changelog here:
https://github.com/tesseract-ocr/tesseract/blob/master/ChangeLog
We see that version 2018-10-29 - V4.0.0
the version in that buildpack is:
https://github.com/pathwaysmedical/heroku-buildpack-tesseract/blob/master/tesseract-ocr-4.0.tar.gz
So I'm guessing that the buildpack version doesn't support getting the image via URL. I bet when you run it locally you have 4.1 and not the older 4.0?
You could fork that buildpack, get the latest source and compile it with libcurl, or you could try download it to a tempfile and then pass that tempfile location to the library. Though that's not awesome for a variety of reasons and you probably want to delete it when you're done.
If I'm wrong about the version numbers please let me know.
If you install httparty, you could do something like this to test it
url = 'https://www.drillster.com/info/img/screenshot-ticket-received.en.png'
File.open("/tmp/test_file.jpg", "wb") do |f|
f.write HTTParty.get(url).body
end
image = RTesseract.new('/tmp/test_file.jpg')
image.to_s
# "Requested ticket\n\nTo make this test, a user must have a ticket....."

How can I tell if a vendored gem is being used?

I have inherited an old project that was previously passed on by multiple developers. It's in a bad shape so I'm trying to bring it back to life. I notice there are some gems and libs that have been vendored into the project but can't tell if they are being used or what!
How can I workout if some of those gems are no longer being used by the project?
A convenient way of checking this is by using a REPL. I would recommend installing the pry-rails gem, which will simply replace the default rails console (IRB) with the arguably more powerful Pry REPL.
#Gemfile
group :development do
pry-rails
end
Run bundle install, and than start the Rails console with bundle exec rails c. Once you are within Pry, you can use its built in show-source command to look up where a specific method has been implemented. Example:
>> show-source ActiveRecord::Base.establish_connection
From: /home/andrea/.rvm/gems/ruby-1.9.3-p125/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/connection_specification.rb # line 128:
Owner: #<Class:ActiveRecord::Base>
Visibility: public
Number of lines: 11
def self.establish_connection(spec = ENV["DATABASE_URL"])
resolver = ConnectionSpecification::Resolver.new spec, configurations
spec = resolver.spec
unless respond_to?(spec.adapter_method)
raise AdapterNotFound, "database configuration specifies nonexistent # {spec.config[:adapter]} adapter"
end
remove_connection
connection_handler.establish_connection name, spec
end
For more usage examples on how to use this specific built-in command, refer to Pry's inline help system:
help show-source
Or have a look at the Source browsing page, on Pry's wiki.
there are some simple tricks that help you do that. you could for example put an puts caller i the root files of the gems and see if they get called from somewhere.
you could also use tracing functionality built into ruby like: http://apidock.com/ruby/Kernel/set_trace_func
or use external tracing tools.

Use a .rvmrc file from a Ruby script

Backgound
A little background to this question first: Ruby on Rails has some security issues as of late. So we need to update the Rails version on our projects. If you have a few, that gets old fast if you do it by hand... So I figured I can create a Thor task for this.
Question
This now works great! BUT! I need to respect the .rvmrc file for each project while installing the new versions of rails. I want this script to be OpenSourced soon, but I want to tacle the problem of not respecting the .rvmrc file first.
So what I need is a way of using the right RVM ruby version/gemset when I change to a directory to update the Rails version.
How is the way for this to be done? Can it be done from the Ruby script in a way so that it works on Mac and Linux, regardless of Shell (found a answer with zsh support, but what about all the other shells out there?)
Quick Example code:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
Dir.chdir(project_folder) do
#TODO: Respect/load the rvmrc file in this directory
update_gem_file(project_folder) #example
run 'bundle update rails' #<--- needs to be done in the RVM gemset
end
}
Just to give you an idea of what I'm trying to do.
Link to the script on the githubs
The github repo for my script -- Work in Progress!
Check out this project https://github.com/versapay/bundler-auto-update it basically:
Attempt to update every single gem of your Gemfile to its latest patch, minor then major release. Runs a test command to ensure the update succeeded
As for RVM use this simple code:
#Scan the base directory down for Gemfiles
gem_files = File.join("**", "Gemfile")
Dir.glob(gem_files){|gemfile|
project_folder = File.dirname(gemfile)
puts "Found Gemfile in #{project_folder}"
run "rvm in #{project_folder} do bundle-auto-update -c rake spec"
}
You can find more details on scripting with RVM on https://rvm.io
Blindly upgrading Rails is not a good idea. At least run your test suite to ensure nothing breaks. After that you still want to do some QA on the app to make sure you didn't break all the things.
Then, How do you know that the current branch you're updating is actually the main develop branch? Don't you want to create a 'hotfix' branch and apply it to your production and development branches?
But, let's say you did manage to upgrade all your apps, they are still not deployed to production.

Install barista/coffeescript on Rails 2.3

I am trying to get barista up and running in a Rails 2.3 application (that may not be moved to a new version of rails for the time beeing..). I switched the app to bundle so I added the following gems to my Gemspec:
gem "barista"
gem "json"
Then executed bundle install which run through. Now as far as I understand to "compile" the coffeescript there is a rake task that comes with barista. But it doesn't seem to be installed properly so I can use it with rake. I.e. when I execute rake -T there is no barista:brew
I saw a pending pull request on git hub suggesting to add require 'barista/tasks' but that only resulted in rake not finding it. So what am I doing wrong or more general how do I get up and running with barista on Rails 2.3.x?
It has been some time ago since I used Barista and I have it not in use in any project, so I cannot verify it.
But I remember that one advantage of Barista is, that it waits serving a request until a modified CoffeeScript file is recompiled. This ensures that the browser doesn't request an outdated file.
So there is no need to compile the CoffeeScript files with a Rake task.
CoffeeScript itself comes also with a watch function, that compiles CoffeeScripts when a change is detected:
coffee -w /path/to/scripts
The reason why I stopped using Barista is simply that I discovered Guard. So I wrote guard-coffeescript to compile my CoffeeScripts in the same moment I save the file.
Guard-coffeescript has some advantages over Barista and CoffeeScript:
Fast and low CPU consumption because it relies on file system modification events.
Can be configured in many ways, e.g. multiple source folders and output folders.
Immediate feedback when an error occurs, even with system notifications like Growl.
Note that Rails 2 support for Barista is, according to Barista's README, "untested" (it was originally built for Rails 3 only), so there may be compatibility issues. Also note that you need either therubyracer gem, or the node binary on your system's PATH (or any of the other JS runtimes supported by ExecJS).
Try this:
Add a file named foo.coffee to the folder app/coffeescripts with the contents
alert 'Hello, Barista!'
Now add <%= javascript_include_tag "foo" %> to an ERB file and load that page.
You should get the alert, just as you would if the compiled foo.js were in public/javascripts.
I've successfully integrated barista and rails 2.3.14. In development, when I ask for a js file, the coffeescript file is found and compiled on the fly.
I also successfully ran the barista:brew rake task and the js files were generated.
I did notice that for production, unless I include an ExecJS compatible compiler, I need to precompile my js files before a push, which might be another +1 for the guard solution by #netzpirat.
For reference - I'm using Barista 1.3.0 and coffee-script 2.2. Not sure how that affects things, but thought it was noteworthy.
Also, I added a line to load the barista tasks in my Rakefile:
# in my Rakefile
load "barista/tasks/barista.rake"

How to get a rails 2.3.3 application running on Bluehost with fastcgi

Using Your Ruby Gem(s)
You will need to add /home/username/ruby/gems to the include path.
You can do this by **adding the following code to your script**:
$:.push("/home/username/ruby/gems")
What script are they referring to? This is vague... Where do I add directories to the ruby include path?
Got it. Looks like the gem path for a default bluehost install requires some "massaging" to work. :) Following instructions from here resolved the problem for me (relevant parts cut and pasted below as well):
http://www.bluehosttricks.com
A) You will need to have the ability to install gems locally. You can do this by following these directions (via SSH):
1) Add the following lines to your $HOME/.bashrc file (these can be copy and pasted):
export GEM_HOME=$HOME/ruby/gems
export GEM_PATH=$GEM_HOME:/usr/lib/ruby/gems/1.8
export GEM_CACHE=$GEM_HOME/cache
export PATH=$PATH:$HOME/ruby/gems/bin
2) Now modify the applications environment.rb file so that the correct gem path is included. This line should go up at the top before the version of rails is specified:
ENV['GEM_PATH'] = '/path/to/their/home/ruby/gems:/usr/lib/ruby/gems/1.8'
3) Kill off any fastcgi processes that they might have running and the issue should be fixed.
EDIT:
I ended up having to follow ALL the steps in the tutorial I linked above. You have to manually edit the rack fastcgi handler file or else the dispatcher will complain. Apparently this is specific to Rails 2.3.3 (2.3.2 worked fine on BH (allegedly)).

Resources