Easiest way to "goto source code" for Ruby/Rails - ruby-on-rails

As a Ruby/Rails non-pro, I often want to check out the code for a rails method to see how it's implemented...
For example, I was using "form_for", and I wanted to check out the code to see how it works. The slightly lame way I did this was to just google "rails form_for" which takes me to http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html, where I can view the source for form_for.
How do rails/ruby pro's accomplish a similar task? Is there a simple way (without using IDEs) that you can quickly dig this out? Or is it a case of over time learning where stuff is located and find/grep-ing it?
Cheers

I clone the rails repository
git clone git://github.com/rails/rails.git
after I grep on it
git grep 'form_for'
After my Vim editor help my with Ctags to navigate on source code.
If you want some example of code using you can see test unit.

I prefer http://railsapi.com/ both local and remote. Quick search, nice design and magic Show on Github link

Related

Auto code grading system like codecademy's

I'm building a ruby on rails application with most of the views with react. I'm considering using CodeMirror as an editor for users to type in code. I want them to be able to submit the code, and the code will be run through some of my test cases and get results back, similar to how codecademy works.
What are some initial steps to achieve this?
Thank you!
Have a look at the http://reactrb.org site. There is live code editors on there. Source code for the doc site is on github.
If the code examples are in either ruby or JS you can run the test scripts in the browser (for ruby you will use opal-rspec) This makes sandboxing easy.
Sounds like a great project. If you need additional questions or help stop in at https://gitter.im/zetachang/react.rb There are a couple of people there who can help you out with the details.

How to post in a blog without command prompt when using octopress in rails?

I am using octopress gem for implementing blog using ruby on rails. I got some code from
http://www.nickhammond.com/setting-octopress-jekyll-blog-rails-application/
and its work fine.
But my question is for creating a new post every time I have to write code in command prompt like
rake new_post['Hello World']
rake generate
I want something like admin panel where should be textbox, textare and submit button. and when I click on submit button it should be posted. Is it possible to create here using octopress? Please share with me, Thank you.
You're looking at a tool like this.
I haven't used it personally, but that's what I get from a simple Google search.
Personally, I'm using GitHub Pages for my Octopress stuff - I was looking for the same sorta thing you're looking for, and came across this. Obviously this is only handy if you're using GitHub for source, but you could edit your source using Prose, acting as a nice Markdown-friendly interface, and then use something like Travis-CI to compile and deploy.
I haven't set this up yet myself though, so I can't speak from experience. But I plan to. :D

Find all uses of a method in vim

Is there a way to find all uses of a method in vim? I'm using vim as an IDE for Rails with rails.vim. ctags helps to jump to a method definition from usage but not the other way round AFAIK. I'd like to be able to find everywhere (controllers, views etc) that a method has been used.
There aren't any perfect solutions for this in Vim, but you can get close with cscope and grep or ack.
cscope will help you find all references to a symbol. It's made for C and C-like languages, but it does a decent job of matching symbols in Ruby code as well. It's not going to get the context right all the time.
Here's a vim cscope tutorial and a blog post about Ruby/Vim/cscope, and another blog post, both of which include additional tips about navigating Ruby/Rails code in Vim.
Using grep or ack from Vim with quickfix integration is another great way to find symbols. They've got no notion of scope/context, but often a simple search is enough. Using just the built-in :grep command, you can do:
:grep some_method app/controllers
:cwindow
And get the results of the search in the quickfix window, which will allow you to quickly navigate to the matching files and line numbers.
A much better option is the ack.vim plugin, which integrates ack with Vim and makes use of the quickfix window.
If you're not already using a plugin for navigating CTAGS, I recommend Tagbar.
I wrote a gem to do just that: https://rubygems.org/gems/starscope
It parses ruby code properly and exports to ctags and cscope file formats.

Well built rails code for download

I want to get into rails by examining well built code
where can i find typical open source rails project that i can download
and learn from ?
i'm interested in facebook connect integration (facebooker), tag clouds, searching in
my website
I'm not looking not tutorials or screen casts
Thanks!
This question gives a good list
a list of projects with good test-suites
a list of open source rails apps to learn from
Have a browse of ruby tool box and download some open source. For example there's refinery and zena, two content management systems and Rboard, a forum. Depends what you want really but there's plenty out there. Ruby toolbox entries are ordered by github watchers and forks to give you an idea of their popularity.
I really like looking at the commits in teambox.
I find it a bit more complicated. But there's also spree.
There's also devise which is really interesting to look at too.
Finally, I'd recommend you to follow the rails commits (it's the only commits feed I have in my Google Reader).
Gady, this is an extremely rich topic you're asking about and resources are all over the internet. Try starting at http://rubyonrails.org/.
You should be able to find tens of questions just like yours (asked and answered) by searching SO at the top bar.
For Rails, part of it is the building process, so one feasible approach is to read a tutorial like http://railstutorial.org/book
then when in Chapter 2, you will use Scaffold, and at that time, you will have some basic code to look into how a basic Rails app is.
I also suggest you use source control like Git, Mercurial, or SVN to commit different phases of the project, from creating the rails project and then after each step, so you can diff what the changes are during each step.
If you already have Ruby 1.9.2, Rails 3.0.1, and sqlite3, then you can
rails new myproj
cd myproj
rails generate scaffold foo name:string salary:integer gpa:float note:text
rake db:migrate
rails server
and now you can use http://localhost:3000/foos to create, display, update, delete the foo records, and have quite a bit of source code to look at. Most of the customizable code is in app, with css and javascript in the public folder.
Ryan Bates has an excellent series of videos.
http://railscasts.com/
An extremely valuable resource.
Radiant is a CMS that you can download for free and see how it works. It is a great piece of code to look at and see how it works.
I guess that most open source Rails projects are shared on Github, so it may be interesting to browse its Ruby section and look for most watched or most forked projects:
http://github.com/languages/Ruby
Steady stream of new interesting projects to take a look at :)
And don't forget the official:
guides.rubyonrails.org
well there is one "bigger" project on github, waiting for downloading and contribution...
but it's a little controversial because of the security issued they have (had?)
It's still worth a look:
http://github.com/diaspora/diaspora

What components make VIM a good (great) ruby editor?

I'm learning ruby on rails on a linux box and dusting off my VIM skills (skillz?).
When I got started on VIM way back in my c++ days, I had a friend with a great vimfiles folder that had tons of stuff to get started. Starting from scratch, vim is great, but it feels like it could be a lot better.
I currently have:
vim-ruby
buffer explorer
xml-edit (though I don't have it currently working with erb files)
I know that barely scratches the surface of what some more experienced vim/ruby devs have (including the one offs in the vim.rc file).
Is there a list somewhere (or could we create one) of a bunch of the standard vim configurations needed to make programming ruby (and rails) more fun? Is there a zip/tarball somewhere with a good base setup?
take a look at tim pope's repos on git hub. Many, many awesome vim plugins and extensions for working with ruby and rails
http://github.com/tpope
snipMate (GitHub repo) is highly recommended. It enables you to use TextMate-style snippets in Vim.
snipMate is not Ruby-specific: by default, it comes with one file containing Ruby-specific snippets. If you are going to work a lot on Ruby-based code (Rails, RSpec, Shoulda, and the like), it's probably better to use one of the available snippets' collections and customize it as you see fit rather than writing your own snippets from scratch.
There is a pretty nice setup for your VIM environment.
http://github.com/akitaonrails/vimfiles
Just follow the instructions and in a minute or two you will have everything ready for Ruby(on Rails) development.
As Jed has mentioned above - tpope plugin is a "must have" and it is part of the akita vimfiles.
I have this in my ~/.vimrc to quickly see the output of a file I'm working on:
map <Leader>r :w! <bar> !ruby %<CR>
For rails, two essential plugins are rails.vim and the NERD tree, for navigating the directory of the rails project you're working on.

Resources