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

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

Related

Configuring Sublime Text 3 for Ruby on Rails development

I am a beginner in this whole thing. I have previously used Sublime for HTML and CSS practice. Now I want to work on a website using Ruby, but do not know how to set up Sublime for rails, since every tutorial for Ruby has those files in the left side of the Sublime window, like App directory and similar generated somehow. I would not like to work blindfolded. I have tried to find a way to generate those directories, but did not find any step by step instructions. Which are welcomed in this case. I would appreciate those, or if there is a link to some detailed tutorial on how to do that. Thanks in advance for any help!
There is a blog that I hope it would help you in your case.
Here it is: Setting up Sublime Text 3 for Rails Development
The directories you're talking about (app, config, etc.) aren't generated by SublimeText; they're generated by Rails when you create a new application with rails new at the command line.
Once you've created the application, you can open the top-level directory in SublimeText, and you'll see all the directories in your sidebar. For example, if you keep your apps in a directory called my_app, and you want to create a Rails app called new_app, you can do this from your terminal:
cd my_apps
rails new new_app
subl new_app
And you should see something like this:
For more on how to get started with Rails, I'd recommend Michael Hartl's Ruby on Rails tutorial.

How to run Ruby programs in MAC OS Terminal [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to run ruby files?
I am starting to learn Ruby and having a hard time running the Ruby classes in the Terminal.
I created a class in the Sublime Text editor, just "hello world". I can compile using ruby hello.rb,
but how do I execute it?
I went to the terminal in my root directory and typed rails c which gave me a console. Could some one please tell me how to create an instance? Which console do I use?
Ruby is interpreted, so you don't need to worry about a separate compile step. ruby hello.rb is the execution command.
The standard interactive shell (REPL) is irb.
I think, this is very simple task.
Paste in terminal ruby <your script name>.rb
This is all. Ruby is interpreted lang. Compiler doesn`t exist at all. Only interpreter.
I use Ruby only few times, but I think, you must run your method hello.
Your code only create the class and nothing else.
You should firstly learn Ruby and then RoR.
As others have pointed out, running ruby hello.rb does run the script; there is no compilation involved (except behind the scenes in the Ruby virtual machine, but you don't need to concern yourself with that).
Based on the code of the file which you gave in a comment (I've put in line breaks and indentation):
class Hello
def say
puts "hello World"
end
end
... the reason your script doesn't seem to do anything is that it only defines a class and a method but doesn't instantiate the class or call the method. You had the right idea (in another comment) to call h = Hello.new(); after that you can put h.say and it will say "hello World".
(Parentheses are usually not required, including in these two method calls; but sometimes they are important. There are varying conventions, but most Rubyists skip them when calling methods without any arguments, like new and say here.)
EDIT:
rails c is for Ruby on Rails, which is a separate entity from the Ruby language (although it's written in Ruby).

Any TextMate trick/bundle to lookup Rails documentation?

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

Ruby command line MVC framework?

I'm looking to write an app for the shell, *nix mostly. And I'm currently in love with Ruby, especially the 'rails way'.
So if there was a framework that applied rails like concepts to the commandline in ruby then that would be really fantastic.
I'v allready looked into SimpleCommand and Hirb, nothing quite what I was looking for.
To elaborate:
What I'm really looking for is a way to use a rails like (directory and application) structure to create a MVC command line application. So basically something like rails that doesn't respond to http, but instead reads and writes to the console.
Its not a shell, if i wanted that then irb works fine. It would be more like your options are A,B,C and they would work a bit like http links.
You should take a look at boson and hirb [2d] menus. First one for creation of commands, second one - for A,B,C options and custom/dynamic views for outputting data.
Maybe you should try script/console in your rails app. Is that what you wanted?

Are there any iPython-like shells for Ruby or Rails?

I love iPython and am learning RoR along with some libraries like Mechanize and I'd like to be able to easily see what I'm working with in terms of introspection. I would like to be able to type "." + TAB and see.
There is an irb tool to help autocomplete
require 'irb/completion'
You should take a look at Pry (an IRB alternative and runtime developer console). It isn't as advanced as the current version of IPython, but it's the most advanced developer console we have in Ruby.
try IRB http://en.wikipedia.org/wiki/Interactive_Ruby_Shell, or the rails console http://guides.rubyonrails.org/command_line.html. I don't know if either of them have autocomplete, but they are quality tools.
There is an IPython notebook backed by Ruby kernel. Details about the project
Wirble is a convenient, if infrequently-updated way of bringing together some of these tools. It's not quite as complete as iPython, but gets pretty close. Among other things, it pulls in irb/completion.
For rails, you can do the same, but use script/console from your rails' root directory to start irb.

Resources