I'm working on a Rails App with Bootstrap 3. What is the difference between adding bootstrapp-sass to my Gemfile and simply downloading Bootstrap and copying the css and javascript files into their respective folders of the Rails app?
I'd go with a gem because it simplifies the updating process. No manual copy pasting makes me a happier developer.
Also, bootstrap-sass is a port to SASS from the official Bootstrap, which uses LESS.
With gems you can always have the latest version if you keep your bundle up to date. If you copy the files, you will have to update manually when there are newer versions of the framework.
Related
I am trying to learn ruby on rails. I created a new project with Rails 6.1.2.1 for this purpose but it took more than 5 minutes. The problem is after creating the project, it creates a huge 100Mb+ dir which is called node_modules with every possible node_package. This does not make sense as the default behavior. Am I actually missing something?
The node_modules are for your front-end stuff. Now Ruby on Rails supports webpacker with all goodies of NodeJS. It is already in .gitignore and it is normal behavior.
When you want to save your project, you can delete this folder and whenever you need you can use yarn install to get it back.
You can create rails app without installing webpacker
--skip-webpack-install option of Rails new. It still includes the webpackergem in the Gemfile and sets up the resulting project with webpacker configuration (only rails webpacker:install is not run).
I updated my application by moving to bootstrap 3 from version 2 by replacing the css files etc.
I thought I'd upgrade simple_from as well since the old one is probably incompatible with bootstrap 2.
So I ran bundle update simple_form and it upgraded from simple_form (2.0.4) to (2.1.1).
How do I upgrade to the lastest version? and how do I integrate it with bootstrap 3? Do I need to reinstall simple_form using rails generate simple_form:install --bootstrap instead of updating the gem with bundler ? and how come updating the gem didn't update to the latest one?
Thank you for the clarifications on how to migrate simple_form properly.
Bootstrap 3 support for simple_form has not made it into a stable release yet. You can read more here. If you want to install the rc version, which seems to work fine, simply use gem 'simple_form', '~> 3.1.0.rc1' in the Gemfile. (Run bundle install after making the change)
I'm not sure how simple_form generators work, but one way of making sure the configuration is updated is by copying config files from the sample application. The files are config/initializers/simple_form.rb and config/initializers/simple_form_bootstrap.rb.
If there are other simple_form-related files leftover from the previous version, you should probably delete them.
I am developing a Rails app that uses a gem that I am also developing.
Every change that I make in the gem I have to: build, uninstall previously installed gem, install built gem, restart rails app.
You can imagine that it easily becomes a nightmare to make even litle changes in the gem.
I´ve tried to manually load all files that are configured to be loaded by the gem (at Gemspec) but it always seem to be some problem in the loading process, not finding libraries or not loading in the proper order.
Is there a way to set my environment to better develop my gem with my app?
You can just add a file reference to your local filesystem in your Gemfile, like
gem 'new_gem', :path => '~/RubyPlayground/DevGems/new_gem/'
That way you just need a new bundle install after modifying your new gem.
Update
Reading your description again you might not be using rails 32. My suggestion is of course based on bundler at least.
You could always symlink your gem code to lib/ and then include that in your autoreload paths (application.rb IIRC).
I currently have a gem installed on my development machine. Now that I want to use this gem on the production but I could not install it due to some issue with the server. Is there a way that I can convert this gem to a plugin so that I can transfer it to the server?
if no, is there a way to transfer this gem from my machine to the server?
BTW, I'm using an old version of Ruby on Rails (2.1)
Thanks.
Just copy the gem's single source code file into your project's lib directory. https://github.com/ambethia/smtp-tls/blob/master/lib/smtp-tls.rb
Well, if the plugin is compatible with Rails 2.1 you should be able to move the plugin to your /vendor directory, and it should work from there. As mentioned in the comments, the vendor directory is going to be removed and that style of plugins will be removed in Rails 4, but for Rails 2.1 that doesn't matter.
To get the files, go on rubygems.org and find the project homepage. You can probably find the source code for the plugin you're interested in (including a version that's compatible with Rails 2.x) on Github, then just clone it to your vendor directory.
I'm new to Rails and I'm confused about concept of gems & plugins. Can anyone explain them for me?
Plugins are just libraries loaded from a specific directory, gems are loaded via Bundler or RubyGems directly.
Where this really makes a differences is maintenance and management. What happens when you want the latest and greatest authlogic plugin, well you need to update the files in your directory. That doesn't sound so bad when it's one plugin, but what about something that constantly updates? There was/is an existing system for code packaging and distribution (RubyGems), which lends itself to managing such things.
Consider the authlogic example again, what happens if the new version requires some other dependency now? With RubyGems the gem file explicitly defines that relationship, the plugin system does not and such a definition would've been redundant.
With the advent of Bundler in rails 3.x it's become very easy to manage and distribute the gems that your project uses.
TL;DR: Plugins are basically gems without the packaging information.
Plugins are being used less and less so stick with gems. Gems and plugins can do exactly the same thing so that is why they are confusing. However the differences are how they are organized and most importantly how gems are managed such as bundler or config.gem. It is much easier to manage gems and their versions. Plugins must be installed in the vendor folder where as gems can also be installed in that folder if they need to be customized or they can be installed in a gem directory as long as rails understands where that directory is located. When rails started most people used plugins to added functionality but developers quickly realized that gems offered a better way to package and update libraries so most plugins have migrated to gems and fewer plugins are being built.
Gem and Plugin
gem is stored in lib files
A Gem is a packaged Ruby application using the packaging system defined by RubyGems.
plugins are stored in vendors/plugins
A Rails plugin is a packaged Ruby application that extends the core Rails framework.