First step in Ruby on Rails - ruby-on-rails

I am going to learn Ruby on Rails (ROR) , can any one help me how to write a "hello world" program and How can I run the program.

First, you have to install ruby http://www.ruby-lang.org/en/ .
All your things you have to install you find here http://rubyonrails.org/download
Well, i suggest to start with http://rubyonrails.org/screencasts, the 15 minutes weblog tutorial.

Check out _why's poignant guide to ruby.

I got the answer....
we need to use the following steps.
rails appliaction_name
- It will create a directory.
In that directory contains list of files and directories.
app config doc log Rakefile script tmp
components db lib public README test vendor
Change the file mode "777" for public/ log/ and tmp/ file. because the program will write the datas in to the files.
./script/generate controller controller_name
Then it will create the controller_name.rb (ruby file in app/ directory)
Then we can write the codeing in to the app/controllers/controller.rb file.
Then we need to call the function from browser.
Thanks................

Related

Rails: conflict error overwrite /home/username/blog/.gitignore?

I'm desperately trying to run a server and keep getting this mistake: conflict .gitignore
The output is:
rails new blog
exist
identical README.md
identical Rakefile
identical .ruby-version
identical config.ru
conflict .gitignore
Overwrite /home/jules/blog/.gitignore? (enter "h" for help) [Ynaqdhm]
What should I do? I'm using Ubuntu 20.04. I'm an absolute beginner.
When you run command $rails new it tries to create new rails application for you. But inside that folder that you are running this command file .gitignore already exists.
So, all that you need is to decide do you want to use your .gitignore file that already exists in current folder or to overwrite it with default one.
I think you made some mistake and just to make things simplier, try to run your command rails new blog in some separate empty folder.
It seems like you run rails new blog instead of rails s/rails server.
Since it already has all the files of a rails application called "blog", it's asking if it should overwrite the existing files with the new files it is creating because you ran rails new blog.

Where should I save standalone non-ruby scripts in my Rails app?

This is a simple question, but I haven't been able to find an exact answer to it anywhere.
I have a standalone Python script which I am using in my Rails app. What is the appropriate folder I should save it in according to convention, so that I can push it to production (currently running it from my computer's desktop)? I think the answer is lib/assets but I want to make sure.
I don't think there is an exact answer for this question.
If it is a ruby script, it is usually placed in lib or bin.
From the rails folder descriptions in Getting Started with Rails guide:
bin/ Contains the rails script that starts your app and can contain
other scripts you use to setup, deploy or run your application.
lib/ Extended modules for your application.
You could put it in lib/assets folder as it reflects your understanding that it is an external asset used in the system.

Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first

I'm getting this error:
Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first
But I'm not in a rails directory, I'm on the desktop. There's no .bundle files anywhere to be found. Any ideas?
cd bin/
rm -rf rails
This fixed my problem. I was also getting the same error message
"Can't initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
Type 'rails' for help."
I was struggling with this over the weekend, but after lots of prodding and poking got it to work.
The problem for me was that Aptana (I believe) created a second rails script in my local bin directory (~/bin) which was called instead of the system script. This local version was older than /usr/local/bin/rails. After moving aside ~/bin/rails, "rails new fred" worked as expected.
Try creating a new folder or rails app in root folder, under ~/
I was having the same problem this morning and that's because rails was already been there while i was creating my application.
To remove the error just go to bin folder of your application and remove the rails folder, and try to create new rails application in your planned folder using rails new app_name.

cannot run rails server command for already created project

I have got an application which was zipped and I unzipped the files and it gave me a folder with all the required structure of a rails application. But when I am going inside the directory and running the rails server command, its not doing anything, but showing me the list of options rails command can do. What would have been the problem?
thanks
Maybe this will help from app folder try:
ruby script/rails server
As explained by Dave Isaacs, Showing the list of options is what the rails command does when it is executed outside the context of an application (i.e., not in the application directories).
Type the full command, including the /script path to the CLI.
script/rails server
instead of
rails server
where script is the path to the rails command that, in a Rails 3 application, lives in the script folder.
I would assume that the application you got was written with rails 2.x. In that case, you have to start it with
script/server

What to ignore in a Mercurial .hgignore for a Ruby on Rails app

I created a hello world app with rails HelloWorld command. I ended up with many directories:
app
config
db
doc
lib
log
public
script
test
tmp
vendor
Should all this be under sources control? What would be a good default .hgignore file for a Ruby on Rails app folder?
.bundle
db/*.sqlite3
log/*.log
tmp/*
.DS_Store
.orig
log/*
tmp/*
your dev database under db
can be ignored to start with.
The general rule is that if you've typed it by hand it should be in source control. If there are some scaffolding files that you didn't type but that can't be easily generated by your build system and don't often change, add them too. Avoid adding files that can be generated from other added files and non-mergeable files that change often.

Resources