Rails Application templates remove a default gem - ruby-on-rails

When using a rails application template is possible to make so that some default gems (sqlite3, coffescript and sass) are not included in the Gemfile?

I'm sure you've solved this problem in the last 7 years, but for everyone else, the best method I've seen for doing this is to gsub it out of the file:
# Removes sqlite3, coffee-rails, and sass-rails gems
gsub_file "Gemfile", /^gem\s+["']sqlite3["'].*$/,''
gsub_file "Gemfile", /^gem\s+["']coffee-rails["'].*$/,''
gsub_file "Gemfile", /^gem\s+["']sass-rails["'].*$/,''

Yes, just modify your application template file to not include them.
take a look https://github.com/RailsApps/rails3-application-templates
to get a better idea, specifically mongoid templates

Related

Rails 4 + Sprockets: Allowing the use of js.erb files

I am attempting to use ES6 syntax in my Rails 4 app and have had some success between the use of sprockets-es6 (0.9.2), sprockets-rails (3.0.4) and sprockets (3.6.0).
The only issue I'm having is that my files need to end in .es6 in order to enable proper compilation and I'd like to be able to use a .es6.erb or .js.erb file type to allow me to use embedded ruby <%= foo %>.
Does anyone know of a way around this?
This question is a few years old and the OP specifies Sprockets 3.6. But I'm guessing many will find this question when looking for a solution to using erb files with a more modern version of sprockets.
If you're using Sprockets 4 and want to use .js.erb you'll need to 'register_mime_type'.
e.g. add the following to a new file called ./config/initializer/register_mime_type.rb
Sprockets.register_mime_type 'application/javascript', extensions: ['.js.erb']
This is described in Extending Sprockets.

Devise apply css file style to the login form

i'm using devise for authenticate the users in my rails app, i've exported the views by using the comand
rails generate devise:views
i see that the files have a 'blank style' so how i can do for apply to them a mine custom file css?
Add gem in your Gemfile
gem "twitter-bootstrap-rails"
visit link for reference
https://github.com/seyhunak/twitter-bootstrap-rails
http://getbootstrap.com
You can find the generated devise view files in app/views/devise.
Just add needed html elements/css classes the same way you would to other view files.
Keep in mind that this will use your default(application.html.erb) layout.
Probably not the best way, but it works and it's not too messy:
devise uses the global application.scss styles by default.
So I just create a login.scss, signup.scss, etc. in my route assets/stylesheets directory and the add #import "login.scss" at the end of application.scss.
Just make sure these page are imported after whatever global styles you want to make sure they inherit.
Note:
As my application expands I usually end up abstracting everything into distinct stylesheets so my application.scss ends up being a list of imports anyway.
I'm sure there are better ways to do this, but this was the "I'm just a designer and need this to work without overcomplicating things" way,
Installation
Add this line to your application's Gemfile:
gem 'devise-bootstrap-views'
And then execute:
$ bundle
Add some minor css fix to your rails asset pipeline manifest
SASS
*= require devise_bootstrap_views
LESS
*= require devise_bootstrap_views_less
rails g devise:views:bootstrap_templates
If you want to go through in detail , you can refer this link : https://github.com/hisea/devise-bootstrap-views

Rails bootstrap gem monkeypatching method not working

I'm using the excellent twitter-bootstrap-rails gem. There is a helper within that gem (NavbarHelper) which is used to generate Bootstrap navbars with a Ruby helper. I want to monkey patch the gem such that the dropdown lists won't have carets.
So, I looked into the source and found the relevant method here. All I have to do is override it. I created a new file in config/initializers called navbar.rb with the following content:
NavbarHelper.module_eval do
def name_and_caret(name)
"HELLO WORLD"
end
end
Presumably, all of the dropdown titles then should be rendered as "HELLO WORLD" in my app (as referenced by the gem source). However, this is not occurring, and the gem does not appear to be monkeypatched at all.
I tried placing puts NavbarHelper.methods - Object.methods in the initializers file, and there were no results, which makes me think that Rails is not loading the gem correctly before the initializers. I have also checked and verified that the gem is not using autoload for its helpers.
Edit
What may be complicating this is the fact that my Gemfile includes the gem in the following manner:
gem 'twitter-bootstrap-rails', git: 'git://github.com/seyhunak/twitter-bootstrap-rails.git', branch: 'bootstrap3'
I'm not sure if this specific versioning means the monkeypatching doesn't work.
Edit #2
It seems there is only one version of the gem on my system, so I don't think that's the issue. Also, I have tried placing require 'twitter-bootstrap-rails at the top of the initializers file, with no results.
The problem is that you patch the method on this module but the module already got included at this point. Try to define this in your application_helper.rb
def name_and_caret(name)
super("blub #{name}")
end

Ruby gem naming conventions

I'm creating a ruby gem and I've noticed that there doesn't seem to be (to my knowledge) a naming convention for gems. For example, I've seen both:
gem 'foo-bar'
gem 'foo_bar'
Is there some kind of definitive guide/convention for the naming of ruby gems?
The dashed version is for extensions on other frameworks, like rspec-rails and the underscore is for part of the normal gem name and should be camelcased in your classes.
So if you have a gem named foo_bar, the class/module should be named FooBar. If that gem should have a rails extension which ships as a different gem, it should be called foo_bar-rails and the module should be called FooBar::Rails and it should be required as require "foo_bar/rails"
This convention is also what Bundler tries to require.
Admittedly, this convention is not always followed. jquery_rails should actually be jquery-rails and factory_girl_rails should be called factory_girl-rails. But hey, not everything is perfect.
RubyGems convention docs:
Naming gems
Naming patterns
Make your own gem
Turns out that this is answered pretty clearly and succinctly in the rubygems docs: http://guides.rubygems.org/name-your-gem/
(This may be a recent doc addition because I recall searching for this info in the past and not finding it.)
The one advantage is the convention of collapsing foo_bar into module or class FooBar as far as autoloaders go. foo-bar doesn't have a default equivalent.
Generally the underscore version is preferable from a require perspective, but the dashed version does come across as more readable so it tends to get used often.
In a recommendation of #svenfuchs:
underscore => camelized
hyphen => name::space
https://twitter.com/svenfuchs/status/135773593526206464
But it's true that I still see non-coherence behaviors like:
gem 'my_gem`, :require => 'my-gem'
https://twitter.com/#!/svenfuchs/status/135784542819713024

Using Warbler, how do I exclude Active Record from the bundled gems?

When using Warbler, what line(s) do I need to add to config/warble.rb to keep it from including Active Record in the bundled gems. I already have excluded Active Record in config/environment.rb as shown below.
config.frameworks -= [ :active_record ]
I tried the same thing only using config.gems in config/warble.rb, but to no avail.
I haven't been able to try either of these ideas, but looking at Nick Sieger's examples :-
Does the gem name have to be a String rather than a Symbol?
It looks like activerecord maybe being included implicitly because config.gems includes rails and config.gem_dependencies = true. Maybe you need to change config.gem_dependencies to false and explicitly include rails, actioncontroller, etc in config.gems.
It might be instructive to print out or log the value of config.gems from within the warble.rb file.

Resources