I have a complete ruby project on my system that I downloaded from github.com and I want to run it on my Windows machine.
I have already installed Ruby and Rails on my system, but I have no idea how to run this project. The directory of this project is something like:
C:\Users\{username}\Desktop\BitcoinFundi\BitcoinFundi
How would I run this project on my system?
To run your Ruby on Rails application, use the following command:
rails server
This will start the server and you will be able to access the application in your browser at http://localhost:3000. Port 3000 is default and you can change it in the application settings.
To run a Ruby script use:
ruby name_of_script.rb
You should check out various resources and tutorials on getting started with rails.
As you say in your comment this is your first experience with Ruby on Rails, I think you should follow through chapter 1 and 2 (at least) of Ruby on Rails Tutorial. After that you should have a better understanding of how you start up a rails app and configure the DB. You also need a bunch of other libraries and software such as mysql from the sounds of it.
You should also read Getting Started with Rails. Section 4 covers how to start the default rails server.
Here is a guide on setting up a Rails environment for Windows, which is one of many guides, that shows you some of the needed steps to get a fully working environment.
I have a Ruby on Rails data mining app, and I would like to be able to do powerful demonstrations without a complicated user-interface.
Is there any way I can make a ruby console for the web that doesn't run the risk of say...
User.destroy_all
?
Something where I can call
ActiveRecord.disconnect!
unsafe_actions
ActiveRecord.connect!
But where I could also have read priviledges (select, inner join, etc.)
Thanks,
Brian
You can run the rails console in sandbox mode:
rails console --sandbox
or
rails c -s
Any changes you make in sandbox mode will be rolled back upon exiting the console.
(And prefix with heroku run to run it on heroku.)
I'm still new to ruby and i'm in the process to learn it, i'm actually using Xampp for php on windows, but i'm stuck at finding a complete package to install a RoR server just like Xampp without any manual work.
Is there any tool out there?
You can try Rails Installer
One of your choices is to use built in mongrel/webrick server which comes with each rails app. Just type $ rails s at the console and you're good to go. Otherwise I don't think it's particularly useful to deploy an app each time you change something.
I'm new to Ruby on Rails (PHP developer here) and I need to edit an existing ROR project. I've been using Aptana Studio for my PHP projects (switched to Zend after Aptana 2.0) but I've kept Aptana RadRails for my ruby projects.
So what I want to do is to get the ROR project from the server (it's hosted on some linux machine) and import it into RadRails for local development. I've downloaded the files from the server and imported them in a new RadRails ROR project but it doesn't work as intended. Is there anything else I should do ? I've read about 'freezing the gems', switching to production mode and dumping the database for a ROR project upon releasing. Are there some steps needed to undo those operations ?
UPDATE:
The problem that I'm having is that I get various errors when trying to visualize in the browser the pages for different controllers.
ActionController::InvalidAuthenticityToken in
No :secret given to the #protect_from_forgery call. Set that or use a session store capable of generating its own keys (Cookie Session Store).
OR
no such file to load -- xml
This error occurred while loading the following files:
hotels_pro
xml
This leads me to believe that (maybe) I haven't got all the files. On the other hand I have double-checked and I have all the files from the server.
Thanks,
A RoR application is more than just the sum of its source files. There's also the database, gems and a server which exist outside the project directory. Without knowing exactly what doesn't we can only speculate which is causing you problems. Being new to Rails, it's probably all of them. If after all this you're still not up and running a few rounds of "Google the Error" should fix you up.
You'll need to set these things up in your development environment before you can proceed. The following assumes you have a working ruby environment: rubygems installed with the rails, and rake gems. Note any commands and paths that follow are relative to the root of your rails project.
Database:
Start with editing config/databases.yml to find out which database your app will try to connect to. Change it if necessary so it names a local database. Create that database, if it doesn't exist with $rake db:create
If you need existing data to test with you can take a dump from your production database and import it into your working database. How to do this is dependent on the type of database in question. Otherwise you can run the migrations with $ rake db:migrate to produce your development database (assuming the previous developer designed the database with migrations.)
Gems:
Check the config/environment.rb, for your list of required gems. Install all these gems if they haven't been already.
If you're using Rails 2.1 or newer, you can streamline this process by ensuring that all gems are required using the newer config.gem 'this_gem' form instead of older require 'this_gem' declaration. Once all required gems are in this form, you can use $ rake gems:install && rake gems:build to ensure they're all installed.
Server:
Is pretty trivial, all rails instalations come with web brick which is fine for development. But mongrel is also suitable.
P.S. If you're not using some kind of revision control it's strongly advised to set something up before starting. It's not a requirement, but it will likely save your ass at some point.
I know in PHP you have to intrepret a page like index.php, but in Ruby how does it work? I don't know what is the Ruby extension like index.php for PHP. Could you help me?
If you are talking about a command line program this will work.
puts "Hello World"
or if you want an object oriented version
class HelloWorld
def initialize(name)
#name = name.capitalize
end
def sayHi
puts "Hello #{#name}!"
end
end
hello = HelloWorld.new("World")
hello.sayHi
If you are looking for a ruby on rails version of Hello World.
Check the Getting Started Guide for Rails.
You can take a look at this Ruby Programming Wiki on Wikibooks
Code:
puts 'Hello world'
Run:
$ ruby hello-world.rb
Hello world
This is how to write a very simple "hello world" using Sinatra, which is a great way to bring up a Ruby-based website without using Rails. The sample is basically the same as the Sinatra folks have on the front page of their site. It's really this simple.
Install the Sinatra gem along with its dependencies:
`gem install sinatra`
Save this to a file called hi.rb:
require 'sinatra'
get '/hi' do
"Hello World!"
end
Drop to the command-line, and enter ruby hi.rb. After a few seconds you should see something like:
== Sinatra/1.1.0 has taken the stage on 4567 for development with backup from WEBrick
[2010-12-04 11:43:43] INFO WEBrick 1.3.1
[2010-12-04 11:43:43] INFO ruby 1.9.2 (2010-08-18) [x86_64-darwin10.5.0]
[2010-12-04 11:43:43] INFO WEBrick::HTTPServer#start: pid=37898 port=4567:
By default Sinatra serves its pages at port=4567, but you can change it. Read the docs to learn how.
Open a new window in your browser, and go to:
http://localhost:4567/hi
and you should see Hello World! in your browser window.
Sinatra is really easy to work with, and makes a great prototyping and light-to-medium weight MVC-like server. I love it because of its easy integration with Sequel, my favorite ORM, and HAML, which replaces ERB as the templating engine.
Sinatra's Intro doc is a great starting point. The Sinatra Book is a good resource too.
How does it work in Ruby?
Ruby is a scripting language (not compiled) just like php (as you said "you have to intrepet a page") and python, bin/bash, etc...in Ruby you have libraries with helpers and very very cool stuff they are called "gems" (Ruby and Gems :D nice name convention right? BTW this is because Ruby's parent is Perl).
You can organized different files inside one Ruby's project folder, it could be in this case one *.rb file and one "Gemfile" (that's the name without extension) in which you define which "gems" you want to install in your Ruby app (read about bundler), only with this two files you will be able to successfully do anything you want but as a desktop app (by this i mean that the Ruby app you write will only be executable on a computer with Ruby installed, and you have to install it manually (with bundler so all required "gems" are in there) and then manually run Ruby's command targeting your code's main class (unless of course you create a cron-job that do this automatically for you, pretty common practice to run processes on web servers).
If you want to use Ruby to create a "webapp" , website , etc right now two pretty popular choices are using the "rails" framework and "sinatra" gem.
With rails (that's why you hear much about ruby on rails) framework you are able to execute commands to create new website project, remember that rails uses the coding pattern called MVC (model view controller) so you will have plenty options for creating your models, views and controllers individually or using "scaffold" that will create all of them for you, rails will create a bunch of files and some of them will not be *.rb of Gemfile, all of them will have a specific task: configuration files for database, labels, of config or other "gems" you install besides rails.Take in mind that rails offer stuff for TDD (test driven development) so in a matter of hours you can have a fully functional website 100% tested and operational (big infrastructure).
This is why i also brought "sinatra" gem to this conversation...sinatra will give you same functionality than rails does but instead sinatra will not install anything for you (leaving space for error if you have not expertise on setting on web servers, web apps , etc) only the sinatra framework which will run a server for you on a specific port number so that way you can then add code to your main class in order to display HTML(small infrastructure)
What is the Ruby extension like index.php for PHP?
All ruby files are using *.rb
Hope this helps!
PS: Hello world sample
install ruby
create a new folder an inside create a file "hello.rb"
open the file and add the following code:
puts 'Hello world'
close and save the file
now open a terminal, console, etc go to your ruby file folder path and run the following command:
ruby hello.rb
that will print on your console:
Hello world
puts "Hello, World!"
To run Ruby scripts on the web, you need to use a special server, run through (F)CGI, or do some other stuff; there are several ways to get different languages HTTP-accessible. However, the simplest way is probably to use a Ruby web framework, such as Ruby on Rails or Merb -- these projects include servers and all of the things you need to get going.
Just copy and past this code on your terminal. Then hit enter.
ruby -e "puts 'Hello world'"
I know the question was talking about Ruby, but I think you meant rails (which is what it was tagged as). Rails is a web framework that uses the ruby programming language.
install rubyonrails.
Type:
rails projectname
cd projectname
ruby script/server
Navigate to http://localhost:3000