RubyMine doesn't show rails source - ruby-on-rails

When I open the Gemfile inside RubyMine I can Ctrl+Click on every one of the gems and RubyMine will take me to the gem's source files. Except 'rails'..
In my current project it's
gem 'rails', '3.2.13.rc2'
And I also can't see rails in the 'External Libraries' section.
Any idea how to solve this?

Rubymine is working fine, that's an 'issue' with Rails itself. Unfortunately, I don't have enough knowledge to say it for sure, but I suppose Rails 3.2.x folder is just a stub. I've tested that in my projects and indeed, project using Rails 3.2.13 have empty rvm rails-3.2.13 dir. I've downgraded it few times and rails-3.1.12 contains a single file rails.rb which just requires `railties-3.2.1/lib' where whole Rails are.
I have also another project using Rails 2.3.5 and there rails-2.3.5 contains Rails files, I have also another one using Rails 4.0.2 (why work with one project if you can work with few? ;)) where rails-4.0.2 dir contains only guides.
So, to answer your question: Rubymine sees empty rails-3.2.13.rc2 dir so it can't show you its source. To look into Rails source open railties-3.2.13.rc2/lib/rails directory.

With the helpful information in #zrl3dx's answer I did the following:
Going to some external library in RubyMine to see where it's looking for source files. In my case it was in
~/.rvm/gems/ruby-2.0.0-p247/gems
Then I copied the railties directory to the rails directory
rmdir rails-3.2.13.rc2
cp -a railties-3.2.13.rc2 rails-3.2.13.rc2
Then RubyMine automatically detected the source code and I can happily Ctrl+Click once again :)

Related

Ruby on Rails - node_modules file is too big

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).

Why do I need to run bundle install after I reformatted my computer?

I'm very new to ruby on rails which is why I'm trying to get a basic understanding of how it works. I have just created my very first rails app which is located in my dropbox folder. As I reformatted my computer two questions arise.
1) I had to do bundle install again in order to launch my local server. Why is that?
2) Also, prior to reformatting, I did cmd+p in sublime to search for files. However, files within gems didn't show in the results - now they do.
Everything works just as it did before I reformatted, I'm just trying to understand those two elements.
Thanks in advance!
Gem are not stored within your project.
If you are using RVM to maintain ruby version then gems are stored within that rvm folder.
As you have formatted your PC, it has removed gem folder from your system.
So, it is requesting for "bundle install".
This command will installing gems listed in applications GEMFILE.
If gem are already present in gem folder then it just use it for your project.
Gems that you require in your project are not stored in your project they are normally stored in a gems folder within your ruby install folder which would be on your local drive.
If for instance your start a new rails project you would see when you run bundle install every gem it checks for would already be installed becasue it's looking into the local gems folder.

Convert a Gem to a Plugin in Ruby

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.

"could not locate gemfile" when doing bundle install on existing rails project

I've been given an existing rails project that I am trying to play around with. however, when I try to run bundle install or rake db:migrate, I run into problems so essentially, i can't really do anything with the code I've been given.
The biggest problem as I see it right now is the fact that it can't locate my gemfile when I bundle install?
How can I find my gemfile.. is there supposed to be one in the root folder of the application?
Is there another step I need to take to initialize an existing project that someone has just copied and pasted to me? Thanks!
Yes, you should have a Gemfile in the root directory of your app.
If you are developing in a Rails 2 app, you might want to check out the Bundler.io page about Rails 2.3:
http://bundler.io/v1.7/rails23.html
If you are using Rails 3+ you can take a learn from Bundler's page on Rails 3 use:
http://bundler.io/v1.7/rails3.html
If you just need to get started with a Gemfile, go to a different directory and generate a dummy app:
$ rails new temporary-app
Copy over the Gemfile to your directory. It will only have the default gems listed, but you may be able to "discover" your needed gems as you go. If you happen to have a Gemfile.lock file then you can see the gems that you need at the top of the dependency tree.

Where does rails source file locate?

Hey guys
I'm new to rails, I read something about reading source code is good way to study rails, and I found the related rb file in rails' online document, such as this page
But I can't find where the rails source file locate in my mac, could someone to help me out?
Easiest way is to look online at the github repo
If you want to browse it locally, you can (depending on your version of rails) to a bundle show rails for Rails 3.0, this will tell you where it's installed.
For rails 2.3.x you just need to find out where the gem is installed and open that up. If you're using RVM for instance it will be somewhere in ~/.rvm

Resources