Please i am new to rails a i want to generate an ER diagram for my application, i found that using rails-erd gem was an option which depended on Graphviz i have install the Graphviz application but can't figure out a way to make it visible in my rails application. I get the following error each time i run rake erd in my rails application.
$ rails erd
rails aborted!
Unable to find GraphViz's "dot" executable. Please visit
https://voormedia.github.io/rails-erd/install.html for installation
instructions.
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => erd => erd:generate => erd:check_dependencies
(See full trace by running task with --trace)
I just figured it out!!!
the reason it is not working is because Graphviz is not been seen by rails.
To solve the above issue, i just included Graphviz to my class path, and restarted my system, after which it started working.
The following steps needs to be taking:
Download Graphviz for windows and install.
Add the path to dot.exe which is located at C:\Program Files (x86)\Graphviz2.38\bin to your class path.
Add the gem to your gem file.
Install rails install gem rails-erd.
Generate your er diagrams by simply typing rails erd and an er diagram would be generated in a pdf file (erd.pdf) would be generated in your project root directory.
I am creating a Redmine plugin and would like to use Haml for the view templates. There is an existing plugin which has Haml views (ekanban) and it does not contain any special code to get Haml working other then having you add require 'haml' to your main application's Gemfile.
So here is what happens -- the templating system loads the .html.haml file correctly but renders the HAML markup (like it was rendering ERB).
I've tried to insert the require 'haml' at various intervals to no avail. I've even tried manually trying to activate Haml.init_rails(...) as suggested in this SO question. I've tried inserting that in a few places, tried it in a Rails.configuration.to_prepare block in the plugins' init.rb file. I've tried telling the Gemfile to not require 'haml' and attempting to do it during plugin load to no avail. What gives?
The view template had Textile in it and I did not notice because the markup for <h2> is similar (h2. vs. %h2). Including gem 'haml_rails' in the plugin's Gemfile is sufficient with no extra code.
Read carefully Installation instruction for this gem :)
Add "gem 'haml'" to your #{RAILS_ROOT}/Gemfile
I can't agree with this strategy: plugin can't change Redmine core! Any Redmine plugin can have own gems (defined in own Gemfile) - so I think you can create Gemfile in your plugin, run bundle install from the Redmine root and I believe you will manage to use Haml
I have comfortable-mexican-sofa gem installed for my app. It has haml-rails as its dependency. So when I run rails g scaffold scaffoldname I get files with .haml extension in the view. But I don't want .haml I need .erb files to be generated. How do I do that?
You can set your default template engine as erb.
See the documentation here for changes you can make in your config/application.rb.
Currently, I have a Rails 3.2.9 Engine which is using sass-rails. When I generate a controller with a couple actions, the assets are also generated (i.e., javascript and CSS). However, both the Javascript and SASS are *.js and *.css files. They're not CoffeeScript (*.js.coffee) or SASS (*.css.sass). Any ideas how to get this work?
Here's a different solution which will use the coffee-rails and sass-rails gems by default - also fixes haml-rails.
I added this to the top of my engine.rb file:
require 'rails'
require 'coffee-rails'
require 'sass/rails'
require 'haml-rails'
What I did was inspect the source code of these files to see how they work in a normal Rails application. For example, in haml-rails I looked at lib/haml-rails.rb and saw the following:
require 'haml'
require 'rails'
module Haml
module Rails
class Railtie < ::Rails::Railtie
if ::Rails.version.to_f >= 3.1
config.app_generators.template_engine :haml
else
config.generators.template_engine :haml
end
...
Similar files exist for sass-rails (lib/sass/rails/railtie.rb) and coffee-rails (lib/coffee/rails/engine.rb).
Just append --stylesheet_engine=sass --javascript_engine=coffee to your generator command (I'm assuming rails g controller).
I'm doing an engine here, it works alright in stand alone.
When I transform it into a gem, and load it inside another application, I get a lot of undefined errors, coming from my engine gem's dependecies.
Here is the gemspec:
s.add_dependency('paperclip')
s.add_dependency('jquery-rails')
s.add_dependency('rails3-jquery-autocomplete')
s.add_dependency('remotipart')
s.add_dependency('cancan')
In the application, when I do a bundle install, it lists all these dependencies, but as i run the application I receive a lot of undefined methods errors (has_attachment from paperclip for example). It seems that the application doesn't load the engines dependencies.
Is this the default behavior? Can I change it?
Same thing happened with a plugin inside the engine.
If I insert by hand those gems, in the application Gemfile, all works...
Include them in your gemfile and run bundle install. Then require them in your lib/<your_engine>/engine.rb file. Don't forget to require rubygems
require 'rubygems'
require 'paperclip'
require 'jquery-rails'
require 'rails3-jquery-autocomplete'
require 'remotipart'
require 'cancan'
Then in your host app (The app where you included your gem) run bundle install/ bundle update (bundle update did the trick for me) and then everything should work perfectly. You can also test this by starting the console in your host app and just type the module name e.g.
Loading development environment (Rails 3.0.3)
irb(main):001:0> Paperclip
=> Paperclip
Hope this helps
You can require them manually like Daniel posted, and you can also require them automatically. You need to add dependencies in 3 files:
yourengine.gemspec
s.add_dependency "rails", '4.1.0'
s.add_dependency "sqlite3"
Gemfile
# Imports dependencies from yourengine.gemspec
gemspec
lib/yourengine.rb
# requires all dependencies
Gem.loaded_specs['yourengine'].dependencies.each do |d|
require d.name
end
require 'yourengine/engine'
module Yourengine
end
Update: It's a simplistic demonstration of how to require the dependencies. You should test it and filter unwanted items, for example: require d.name unless d.type == :development (thx #imsinu9)
from paperclip's README :
For Non-Rails usage:
class ModuleName < ActiveRecord::Base
include Paperclip::Glue
...
end
I had the same issue and that fixed it for me.
You must add the gem file to both the .gemspec file, and your engine.rb file.
In the .gemspec file it would be like:
s.add_dependency "kaminari", "0.16.1"
In the engine.rb file at the top add:
require "kaminari"
I think you also need to add the gem to the rails engine Gemfile and bundle install, but I'm not certain if you need it there.
At the time being (Rails 3.1 and above I think), you shouldn't have do declare any gems in the test/dummy/Gemfile anymore:
Quote from test/dummy/Gemfile (generated using rails plugin new my_engine --full):
Declare your gem's dependencies in simple_view_helpers.gemspec.
Bundler will treat runtime dependencies like base dependencies, and
development dependencies will be added by default to the :development group.
Declare any dependencies that are still in development here instead of in
your gemspec. These might include edge Rails or gems from your path or
Git. Remember to move these dependencies to your gemspec before releasing
your gem to rubygems.org.
You really shouldn't need them on the Gemsec, and they should be loaded. When you say "here is the gemspec", you are surrounding it with Gem::Specification.new do |s| or something to that effect, right?
You can include all gems for the environment with a simple bundler command:
Bundler.require(*Rails.groups)
You could add this to an config/initializer.