How to run a Ruby project - ruby-on-rails

First of all I am not Ruby developer, hence my hopefully really simple question.
I inherited a project with the following folder structure:
Capfile
Gemfile
Rakefile
app
config.ru
config
db
doc
lib
public
script
spec
vendor
My question is:
how to run this project in local environment? I'm running MAC OS X and have Ruby and Apache installed
from the folder structure, are you able to identify framework/frameworks this project is utilising?
Thanks for you help!
Marcin

Maybe it's a Ruby on Rails project. Try these lines in the console in the project folder:
gem install bundler
bundle
rake db:create && rake db:migrate
rails s
These commands will start Rails server at localhost:3000. This project requires DB to be installed. (DB type depends on Gemfile content). Also you should check if config/database.yml file is present.

Old question, but I would open up the Gemfile and see which framework is being used. It is often the first gem in the list.

Related

rails web config folder does not have the webpack folder eventhough I setup the foder without error?

here is my problem.
I setup a very simple website by rails command and here is my command
rails new freelancer --database=postgresql
and I meet no error
I used postgre sql and postico to test the database and saw the database.
In the file database.yml, there are 2 databases and I ran this command
rails db:setup
rails db:migrate
In postgre sql I also saw the database, maybe it is ok.
But my problem is, I do not see the folder webpack as the tutorial, the folder webpack must like this : (folder) freelancer > (folder) config > (folder) webpack
But I do not see it.
Must I run this command ? To create this folder ?
rails webpacker:install
Could you please give me some advices ? Thank you very much for your time.
Look at Gemfile file, there should be the gem 'webpacker', just run 'bundle install' for installing all the gems that will be used in the project.
If you dont have that one in the Gemfile, just add it like:
gem 'webpacker'
Then it should all be done, but if you still not see the folder, use the command you are saying:
rails webpacker:install

"Could not find generator figaro:install"

I'm using the "Learn Ruby On Rails" pdf book from learn-rails.com.
I'm at chapter 13, "Configure". Where we are supposed to do the command: "rails generate figaro:install"
In chapter 12 we installed the figaro gem,: "We’ve already installed the figaro gem in the Gemfile and run bundle install."
When I run that command I get: "Could not find generator figaro:install."
I started searching for similar questions, and I did find this question here: rails generate - "Could not find generator"
where they were recommended to include "migration" into the command as well.
I included it in my command and I got it to do something, but I don't think it's doing what it should be?
invoke active_record
/Users/NormalUse/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activerecord-4.0.2/lib/rails/generators/active_record/migration/migration_generator.rb:57:in `validate_file_name!': Illegal name for migration file: figaro:install (ActiveRecord::IllegalMigrationNameError)
(only lower case letters, numbers, and '_' allowed)
from /Users/NormalUse/.rvm/gems/ruby-2.0.0-p353#learn-rails/gems/activerecord-4.0.2/lib/rails/generators/active_record/migration/migration_generator.rb:10:in `create_migration_file'
Then about 20 more lines as well. I just didn't want to put it all here.
The author goes on to say:
"Using the rails generate command, the figaro gem generates a config/application.yml file and lists it in your .gitignore file. The .gitignore file prevents the config/application.yml file from being saved in the Git repository so your credentials are kept private."
When I go to my project directory, and look inside the "config" folder, I do have an "application" file, but it ends with ".rb" and not "yml". So obviously the command didn't do what it is supposed to do, right?
Does anyone have any ideas for me?
I'm using Ruby 2.0.0 and Rails 4.0.2 with RVM on Mac OSX 10.7.5
If you do this tutorial nowadays instead of "rails generate figaro:install" run command "figaro:install" due to figaro 1.0.0 version https://github.com/laserlemon/figaro
As you're learning (welcome to the Rails community btw!), let me explain what Figaro does & how to use (install) it:
Figaro
Figaro is a way to create ENV variables in both development & production. It's a gem which you have to install before invoking from the Rails cmd
Like other Ruby gems in Rails, you have to add it to your Gemfile, which lists all the plugins your app will use. According to RubyGems.org, you could list it in your Gemfile like this:
#Gemfile
gem "figaro", "~> 0.7.0"
After you've added this line to your Gemfile, you need to install it. To do this, you should run bundle install to run the bundler (installer)
Once you've done this, you need to run this command from cmd:
rails generate figaro:install
Error
Your errors seem to indicate you've got migration problems?
Illegal name for migration file: figaro:install
(ActiveRecord::IllegalMigrationNameError)
I would guess you called this command:
rake db:migrate figaro:install
If this is the case, you should perform any migrations by running rake db:migrate and then rails generate figaro:install. This will run the commands separately, which should help them work
Please try below one:
bundle exec figaro install
Thank you

Cannot running 'rake db:migrate' on a cloned github repo

Since I am new to rails and have learned the very basics from books I now figured that I can learn quite a bit more from reading other peoples code and trying to make sense of it so I have signed up at github and set up everything there. Now I read that one good open source project to learn from is radiant so I went to https://github.com/radiant/radiant and cloned it to a local directory. THen I proceeded as follows:
cd radiant
bundle install, which went fine
rake db:migrate, which first returned:
rake aborted! You have already activated rake 0.9.2, but your Gemfile requires rake 0.8.7. Using bundle exec may sol
So I typed in bundle exec rake db:migrate and recieved the following:
NOTE: Gem.source_index is deprecated, use specification. It will be removed on or after 2011-11-01. Gem.source_index called from c:/Ruby192/lib/ruby/gems/1.9.1/gems/rails-2.3.14/lib/rails/gem_dependency Rake aborted! No such file to load -- radius
So here I am wondering how to fix this problem? I also noticed that a Gemfile and a Gemfile.lock already existed in the radiant folder when it was cloned, which perhaps could be part of the problem?
Also I wonder if it is crutial that I run the same version of rails as the project is written in?
Now it should be said that I currently have rails 3.0.5 installed and run on windows
I hope someone can help me here, it has been quite frustrating since I have not been able to run any cloned github repos (radiant here just being one example).
You should edit your Gemfile and make it require newer rake.
Also you can run rake db:migrate --trace to get additional error information.
The deprecation warning is still just a warning, and it shouldn't be causing you any issues. The part of that error that is relevant is the No such file to load -- radius. You probably need to follow the instructions for installing Radiant, which include running a gem install radiant before dropping this project code somewhere.
Bundler manages installing and using the gems in your Gemfile, and if a Gemfile.lock is present it'll use those exact versions. This means you can't run Radiant with Rails 3.0.5 since the Gemfile specifies 2.3.14. Bundler will install Rails 2.3.14 and its dependencies automatically, though, so you don't need to worry about it.
By the way, this project looks like it has been very mismanaged. It's not common for a Rails project/gem to force you to actually clone it to use it. If you want to check out a Rails 3 project to learn from, I have a slim Rails 3 app that was intended to be an API up publicly on Github with some really clean code: http://github.com/coreyward/instavibe

"could not locate gemfile" when doing bundle install on existing rails project

I've been given an existing rails project that I am trying to play around with. however, when I try to run bundle install or rake db:migrate, I run into problems so essentially, i can't really do anything with the code I've been given.
The biggest problem as I see it right now is the fact that it can't locate my gemfile when I bundle install?
How can I find my gemfile.. is there supposed to be one in the root folder of the application?
Is there another step I need to take to initialize an existing project that someone has just copied and pasted to me? Thanks!
Yes, you should have a Gemfile in the root directory of your app.
If you are developing in a Rails 2 app, you might want to check out the Bundler.io page about Rails 2.3:
http://bundler.io/v1.7/rails23.html
If you are using Rails 3+ you can take a learn from Bundler's page on Rails 3 use:
http://bundler.io/v1.7/rails3.html
If you just need to get started with a Gemfile, go to a different directory and generate a dummy app:
$ rails new temporary-app
Copy over the Gemfile to your directory. It will only have the default gems listed, but you may be able to "discover" your needed gems as you go. If you happen to have a Gemfile.lock file then you can see the gems that you need at the top of the dependency tree.

Local copy of Rails in a rails application

I recently upgraded a rails project I am working on from 2.0.5 to 2.3.2. I noticed that there was a local copy of the 2.0.5 rails files in vendor/rails and I was wondering should I put a local copy the 2.3.2 rails files in there too or just leave them out? What is considered a better practice?
Yes. The copy of Rails that sits in vendor/rails is actually used in preference to the Rails gems installed system-wide—in other words, though you upgraded your Rails install, your app is actually still running on 2.0.5.
The vendor/rails directory exists so you can "freeze" your app to a specific version of Rails, thus making it less vulnerable to changes in the configuration of the machine it's running on. This is so darned useful that there's an automated way to manage the directory. To delete the existing version of Rails sitting in vendor/rails, go to the root of your Rails project directory and do the following:
rake rails:unfreeze
To then install the most current Rails gems on your system into vendor/rails, do:
rake rails:freeze:gems
There are a few other things you can do with vendor/rails. Check out rake -T for a full list of commands.
P.S. If you ever hear someone talk about their Rails install being "vendored", this is what they mean.
In the meanwhile things have changed a little.
rake rails:freeze
and
rake rails:unfreeze
are deprecated. Instead you should use:
bundle install --path vendor/bundle
and
bundle install --system
to switch back.

Resources