Where does rails source file locate? - ruby-on-rails

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

Related

Rails Generate model error in Ruby on Rails

I am building a new RoR app and i had tried to create a new model like below.
rails generate model Pic title:string description:text
But I keep on getting these errors always and I tried installing many methods like installing gems ,updated the gems etc.
P.S : I am trying install the older version of the gems. Is that creating a problem?
But none of it gave me the results. Please help me with this.
P.P.S : I am an absolute beginner to ruby. So please help me by giving solution with good reason. Thanks in Advance.
Hi seems like you have issues with your simple_form gem,try to remove from gem file and add gem 'simple_form' and run bundle install after this step run rails generate simple_form:install for creating config file for simple form.
Try this it may help you out.
As #Navneet pointed out generating a config file can also be used for configuration and it also works pretty well.
Another thing i found was , Here the gems used were older version. That created a compatibility issue(since it was not configured accordingly). So by replacing the gems with current version or stable ones , you can get rid of this problem.
Go to rubygems.org
Search for the gems and check whether its the latest version
If not, Replace the line of corresponding gem in Gemfile with newest one.

Ruby on Rails - Error making new app (rb:55:in 'require')

I've been following Mike Hartl's excellent Ruby on Rails Tutorial`.
I had to make some decisions earlier about versions for gem files and ruby. I decided (after some problems getting Heroku to work that I'd directly mimic the tutorial and versions of ruby described - leading me to go with rvm use 2.0.0 to set my version of ruby.
All was great on chapter one but now I'm getting an error message when i try to create a new rails project:
$ rails new demo_app
/home/huw/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in require': cannot load such file -- rails/cli (LoadError)
from /home/huw/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from /usr/bin/rails:9:in `'
I have no idea what that means... but as its referencing my ruby version I'm guessing that my rails and ruby versions are out of sync...
Could someone advise on possible courses of action?
I imagine possible options would be:
Reset my ruby version to the latest (but I don't know what clashes
that would create with gems!)
Downgrade from rails 4.1 to rails 4 (I believe that's Mike Hardl's version)
Force things through somehow
I'm a complete rails Noob however, and have no idea where to begin on any of those options - or if that error code even backs up my assumptions!
Forgive the "answer" but I don't have the rep to post a mere comment :-(
Have you tried looking at the RVM site? It has a troubleshooting page that may help you.
If not, have you tried get rvm stable and then typing in the rails new app_name command?
Other useful RVM commands are rvm list rubies and rvm gemset list. It may be the case that the ruby version you're using doesn't have rails for some reason.
As per zwippie's answer in the comment section, the solution was achieved as follows.
rails -v produced a very similar looking output to the error message above.
gem install rails after hanging for a second installed rails successfully. I am now able to add a new project.
I'm unsure why this has happened as I've been successfully making new rails projects both on this laptop and in this directory for the last two weeks, even up until this morning. However as zwippie notes perhaps this is an RVM setup issue. I'll go away and read up but if anyone had any additional pointers from documentation that might shed light on the issue I'm appreciate any links in the comment.
Many thanks all.
check for the rails is installed on your machine by the command bundle show rails.
If you get the version of rails and are still getting the above error, to resolve it you may have to use the command bundle exec before every rails command as in bundle exec rails s.

RubyMine doesn't show rails source

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

When I download a Rails open source project, how can I know which version of Rails or gems is needed?

When I download an open source Rails project, how can I know which version of Rails or gems is needed?
For example, I want to build a blog. Then I do this:
~$ git clone git://github.com/mojombo/jekyll.git
That is a free open blog project. When the clone is 100% done.
~$ cd jekyll
~$ rake db:create
rake/rdoctask is deprecated. Use rdoc/task instead (in RDoc 2.4.2+)
rake aborted!
Don't know how to build task 'db:create'
So what's wrong in my Rails or Gem or any other? Is there a problem of version?
Jekyll is not a Rails project. There is no db:create Rake task.
I'd suggest taking a look # the documentation to figure out how to use it.
Jekyll is not a rails app, however...
I would always start with the project's Gemfile (if they are using bundler), if the developer has specified versions for the gems, this should give you a good look at the specific version requirements.
As Brian and Nate have said, read the documentation about it.
I personally have a Jekyll-powered site that you could use as an example if you're stuck. The documentation contains pretty good examples as well.
But to get you started: Jekyll doesn't really have any database backing to it. You must create the directory structure--as outlined in the Usage guide--yourself.
For generating new posts, I have a script called new.rb in my repository. Simply because I can't be bothered remembering what the Wordpress ID was for the previous post (I imported from Wordpress).
Once you've got a post written, install the jekyll gem:
gem install jekyll
Then run jekyll --server. This will parse the post into beautiful HTML which you can view at http://localhost:4000. Once you're satisfied with it, put it online somewhere with Apache or Nginx serving it as it would any other static HTML site.
Finally, if you're ever looking for an alternative, I've heard good things about nanoc.

Rails Server Command

I am new to Ruby on Rails and am following a tutorial to create a class project.
I can generate a new rails project with
$ rails project
The problem Im having is when I try to start my server, It will generate a project called server:
$ rails server
or
$ rails s
I figured out that I need to install/update rails to 3.0.3 to use this command every time I open terminal. I find myself having to install gems(bundle, etc) every time I need to work on my project.
Is there anyway to save this terminal session or profile for later use?
Is it user error?
Im new to Rails and about the same with terminal.
Any help would be greatly appreciated. I have resorted to leaving my computer and terminal open for about a week...
Welcome on board! - You'll have fun, I found setting up the environment the most difficult thing.
in rails 2 you start the server with ruby script/server.
to upgrade to rails 3 try gem install rails -v=3.0.4
I put the version but it's not a mandatory option.
To uninstall a gem (as rails is) is gem uninstall gemname -v=x.x.x. -
gem list will tell you the version of each gem.
I hope you've got rvm, if not I strongly sugget you to install it, this will allow you not only to use different versions of ruby but also to set different gemsets, therefor one each project, you'll find it useful.
Once in rails 3 you can use bundler, have a look at this episode of railscasts, by the way this is a very good site, but you may know it already.
another edit...
I don't know the behavior you're describing, looks like something is wrong with your environment, but I need to know if you have rvm to solve this, if so try rvm list and rvm gemset, With the first you get the list of installed ruby, you can switch between them with rvm 1.9.2 i.e. and rvm 1.9.2#gemdirname with the gemdir coming from the second list. You should find your configuration in one of those list.
Hi if you are using rails 2.8 or lesser use this to start the server
ruby script/server
rails new project is for new rails project n rails s is for starting server

Resources