Any TextMate trick/bundle to lookup Rails documentation? - ruby-on-rails

I know this is common in 'full featured' IDE's and not text editors but TextMate walks a unique line with its many bundles... I'm wondering if there is an easy way to, say, click on a Ruby or Rails class or method and have TextMate (or shell) take me to the definition or some documentation?

There's one built into the rails bundle (^h) which uses api dock.
Another pretty nice way of doing it is using the rails os x dictionary, but it has a few downsides and I'm not sure what version of rails it's using (I'm pretty sure it's not rails 3, but I haven't checked).

Ctrl-H is an excellent option to learn about Ruby or Rails API.
But this doesn't work for any other methods or class that may be defined or included in your project. For those I've written a TextMate Bundle command (you can easily assign it to Ctrl+] for example) that lookup for the definition of the class or method under the caret and displays it in a tooltip, along with the file name and the line where it was find.
Check it out: Add a shortcut to TextMate to lookup a class or method definition in a tooltip
Hope you'll find it useful ;)

Related

Add a basic UI layer to existing ruby app

First, I am fairly new to Ruby/RoR and so you'll have to forgive me for any wrong terminology, but hopefully I'll get my point across.
I built an ruby app that I am needing to add an extremely simple UI layer using rails. Read up on a previous post of mine that explains the project thoroughly to give you good an idea of what it does. Specifically take a look at the tree outline that I pasted in so you see the existing file structure for the project.
What I need to know, is how to convert this existing project into a rails app? My experience in building something with rails has always started out with rails new app_name, but never anything like this. Any tips would be appreciated.
I saw your parser script, and it is not a daemon (a program that keeps running indefinitely in the background), right?
If I'm right, then you have several options:
The easiest option
Just build a rails application using rails new app_name, and inside some controller action, make a system call to run your script
class SomeController
def some_action
succeeded = system(:ruby, '/path/to/main.rb', '/path/to/some.txt')
# Do some rendering stuff here based on the result of the system call
end
end
This approach is somehow nasty for me, and it's not performant because each system call reads your ruby script and compiles or interprets it then runs it.
The harder option
Refactor your script so that it's features can be wrapped into a gem.
Then you install that gem, require it in your rails app, and use it.
I saw your original ruby script is almost there, it shouldn't be that hard to make it become a gem.
Rails is just "something" on top of Ruby. Especially, you can use any plain ruby objects inside of Rails, anywhere, and this is nothing unusual (google "PORO").
In your case, I would make a simple Rails app in the way you have mentioned yourself with rails new. Then trivially refactor your existing code until you have a simple, standalone class that does what you need to be done but takes its input/output from simple ruby data structures (i.e., method arguments, return values, no global state, no file operations). Then you can use that class from inside your Rails controller (taking input from a HTML form, rendering output to HTML), and also from inside your script (reading input from a file or STDIN, rendering output to STDOUT).
Where you put that class is up to you. In the MVC paradigm, it is not "C" or "V", and one could argue about whether it's "M". So put it into app/models/ or lib/, whatever you like more.
These were great answers and I'm sure they would have worked perfectly. However, they were a little bit more complex than what I was looking for.
What I ultimately ended up doing was just cd into the directory above where the ruby app was located and then just simply ran rails new app_name. Rails will ask if you'd like to overwrite any files that exist already. From there I just integrated my script into the controller actions and created the views.

Does every ruby on rails app need to be written on the console terminal?

I don't like using the console terminal. Is it possible to use a text editor like bracket *(MY FAVORITE) to write ruby code? I've seen ruby files. Are those written on an editor? Or is it the case that all these schools teach you the basics through the console and later you can write code on an editor?
Ruby do not have to be written in the terminal.
I myself do most of my coding in sublime and do run some commands in the terminal to run tests and generate some files. (Rails generators are quite awesome by the way)
I have a colleague who uses Ruby mine and from what I understand you can use that to do rails development without using the console.
Yes obviously you can use text editors.
You can write code in editor save it as file_name.rb and run from console as ruby file_name.rb
And this is just a start with Ruby. Just give your 20 minutes and you will get to know
https://www.ruby-lang.org/en/documentation/quickstart/
When you will get familiar with all the great things about ruby
You can start with Rails, as it's name suggests it actually get you started
http://guides.rubyonrails.org/getting_started.html
Just go on and you get fell in love with Ruby on Rails what it is called.
It's a lot convenient to use text editors and write codes instead of giving yourself a hard time coding using the console.
Sublime Text is one of the widely used editors, very easy to use and free. I've always used this.
You could also check out some of the best editors here 5 Best editors - Lifehacker
You can use any text editor and save the codes with the .rb extension <file-name>.rb and run it through terminal like this: ruby filename.rb

CKeditor not showing Formatted Code

I have installed CKeditor for my Rails app and while doing the Formatting, the Formatted code does not display in the screen, instead, HTML is rendered, like this
<h2><strong>In this project</strong> you’ll create a simple blog system and learn the basics of Ruby on Rails including: Models, Views, and Controllers (MVC) Data Structures & Relationships Routing Migrations Views with forms, partials, and helpers RESTful design Using Rails plugins/gems The project will be developed in five iterations. I0: Up and Running Part of the reason Ruby on Rails became popular quickly is that it takes a lot of the hard work off your hands, and that’s especially true in starting up a project. Rails practices the idea of "sensible defaults" and will, with one command, create a working application ready for your customization. Setting the Stage First we need to make sure everything is set up and installed. See the Environment Setup page for instructions on setting up and verifying your Ruby, Rails, and add-ons. This tutorial was created with Rails 4.0.0, and may need slight adaptations for other versions of Rails. Let us know if you find something strange! From the command line, switch to the folder that will store your projects. For instance, I use /Users/jcasimir/projects/. Within that folder, run the rails command:</h2>
Use the html_safe method
So, something like:
puts my_variable.html_safe
Lots more info here: http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/

tips and tricks for using vim with ruby/ruby on rails

I'm one of those developers who isn't using TextMate with any of his Ruby/Ruby on Rails work. My particular loyalty in this arena lies with vim. What are your favorite tips/tricks for using vim with Ruby and/or Ruby on Rails to make you as efficient as possible when working?
Most important
Get a copy of rails.vim it is awesome on millions of levels. Read the doc. There are way too many tips, :Rview customer, :RSmodel foo, :Rinvert, gf, :Rextract, :Rake and the list goes on and on. You will probably want NERDTree as well for easy navigation (which you can access using :Rtree)
Second most important
Follow tpope on twitter (the author of fugative, rails.vim, haml.vim, vividchalk theme, cucumber.vim and so on), he seems to be posting new related to Rails vim plugins quite regularly (be it syntax highlighting or git integration).
You might want to checkout my ruby/rails specific vimfiles.
Its a useful starting point and has many useful Ruby/Rails plugins bundled and configured.
The one thing that really sucks about Textmate is that it doesn't run on Linux. My vim/gvim config is the same on Mac, Windows and Linux. Same fonts, same themes, same plugins and same customizations.
I mostly use Textmate for snippets and quick evaluations for posting here.
I wrote an in depth guide on using Textmate features (especially Rails related features) in VIM. It's very relevant to this question.
http://www.jackkinsella.ie/2011/09/05/textmate-to-vim.html
I don't use vim, instead, I'm like those millions of developers using Textmate. Nevertheless, a colleague does use vim/gvim.
By looking at him work, one of the things I wish I could do in Textmate is the ease of working on multiple files at the same time. Basically, you can easily manipulate multiple windows, which is quite handy.

Textmate Ruby on Rails Highlighting

I have Textmate 1.5.7 running on my leopard machine.
When programming in rails, for some reason some key words do not get highlighted.
For example: validates_presence_of, has_many, remote_form_for (form_for gets highlighted) etc...
I tried switching themes and it did not help. I also tried upgrading to the most recent rails bundle but no cigar. Could someone please help?
Use RubyOnRails as your language rather than Ruby
If you're editing views like .erb files you'll want to select HTML (Rails) so the remote_form_for, etc. get properly highlighted. For everything else (controllers, models, migrations, etc.) like #Omar points out, make sure you've got Ruby on Rails selected.
Just a quick note for other lurkers -- it took me a little while to figure out how to change languages on TextMate. You can do it through the Bundle Editor, which will show you the shortcut as well...

Resources