Bundler: Create Gem - Default Contact Info Source? - ios

I followed this guide to build my first Ruby Gem:
http://bundler.io/v1.12/guides/creating_gem.html
Everything worked as expected, but I have one question: I noticed that Bundler auto-magically pulled my personal contact info from somewhere (I'm on a Mac) and used that to build the gem. An example of a file containing this info:
gem_name.gemspec
I don't want it to default to using my personal contact info (such as my personal email address, etc.) as I build more gems. I want it to use my company's info by default. I'm guessing/hoping that there is some data file somewhere that I can set this default info, to be used on all further new gem builds? Or maybe some other way to set these default values???
I realize that I can edit this info after the scaffold builds, but I want to automate it as much as possible.

Bundler pulls that info from git so just set your name in your ~/.gitconfig globally:
[user]
email = my#workemail.com
name = MyName
or you could set it locally to that repo via ./git/config.

Related

Is there a way to let Rails push an internal repository to Github while its hosted?

Assume that I have a Rails project. I have published it on a server like Heroku. Think of it as a small app that have to update a git repository (a separate repository in its public folder). Is there a way to achieve this?
For example...
Think that i have some markdown files in my public folder. My rails app will give me an interface to edit these files. When the editing is over, I need to push these files to a git repository. Only that folder through a script in the Rails app.
You can either shell out to git:
Dir.chdir('/path/to/git/tree') do
system = "git commit -m'Updated by rails' -- #{name_of_file_to_commit}"
# Check $?, and do some appropriate error handling if it's != 0
end
Or you can use one of the several ruby Gems for interfacing with git. I am not familiar enough with them to recommend one; in any case, any recommendation will soon be out of date. It's best to do your own search, find candidate gems, and try them.

Why am I getting an error when I bundle install without using "sudo"

Recently I have noticed that trying to bundle without the "sudo" command almost always results in something like:
Could not find gem 'faye (~> 1.0.0) ruby' in the gems available on this machine.
but using sudo bundle install works like a champ.
Why would my computer be doing this?
Note
I don't really know what extra information to provide, so feel free to request anything.
With "sudo" the command is executed by the root user. When executed like this, it also includes that some environment variables are set differently, because they are needed in the context of the root user.
This might be what's happening here, that since possibly the PATH variable (or some other environment variable) is different in the sudo-environment, it can actually find the gem it is looking for. While in your normal execution environment, it can not find it, since the PATH is set differently.
Hope this helps :)
Following up on #topedro's answer: You're seeing this error because you did some actions as root, and some as another user.
Most people avoid this situation by installing Ruby and all gems as the same user who'll be executing them. E.g., your personal user account, or one set up for this purpose on a server named (usually) "deploy".
An easy way to get started from your current broken state is to install RVM as a non-root user, and go from there. You could also download the Ruby source and compile it yourself instead of using RVM.
Whatever you do, treat Ruby and the gems as simply some app owned by a non-root user, residing in that user's home directory.

How do I set up an old Ruby on Rails project on a new server?

I'm not a RoR programmer myself, but a good client of ours has sent a project their previous web team built and I need to get it up and running on their server.
The server uses cPanel and Ruby on Rails is already installed. I've created a project via the cPanel wizard and located the file tree via SSH.
Using SSH, I've tried to replace this file tree with the project I've been sent, but when I hit 'run' in cPanel, the application doesn't actually start (although the success message would indicate that it has).
If I leave the original cPanel-created application in place, I can run/stop no problem and the web interface at :12001 opens up just fine.
I assume there are either conflicts with RoR versions that I need to resolve, or there's simply more to it than just replacing the file tree? Again I'm not a RoR programmer and I'm having a hard time finding a migration guide that tells me anything other than "set up in cPanel and replace the files".
I'd very much appreciate either some genuinely useful links to RoR application setup/migration guides (ideally for cPanel) or a step-by-step answer please.
First, forget Cpanel for now. Try in one environment where you can control everything.
Try to know better the rails version used and the associated gem19s or plugin if from 2.x days. The ruby version is important too, only then you can start defining a plan.
I'm afraid you won't get a step-by-step answer, but I'm sure you can be pointed in the right direction by providing the requested information.
Simple questions: Do you have a Gemfile file at the top at your project? Do you have any plugins (stuff in vendor/plugins)?
Update:
With the Gemfile provided here are the required steps:
Install ruby (if you haven't install it using rvm. The version 1.9.3-x should be the safest.
Install rubygems
Install bundler
Go the project dir and run bundle install
run rake db:migrate (assure you have the database setup acording to config/database.yml
run rails s and check the logs and see if the server is up.
If after installing bundler, you don't have the bundle command in your path, you need to add this your .bash_profile:
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export PATH

Rails 3.1 application deployment tutorial

I'm looking for a good deployment tutorial for a Rails 3.1.1 application on a server. And by good I actually mean complete. The reason I'm posting this question is that although there are tons of tutorials out there on the web (google, blogs, books, other stackoverflow questions etc...) all of them seem to focus either on a problem with the deployment process or make some assumptions about the deployment environment that do not match with what I need.
I realize that deploying a Rails app on a server requieres a variety of different programs and tools that need to be configured and somehow I always get stuck on apparently "little" things that make me very frustrated.
So, let's begin from the start. What I have now is a server that I can access through SSH and a domain name, let's call it www.example.com. The server runs a fresh Ubuntu 10.04 x64 and has just a user installed, namely root (through root I access the server with SSH).
Note! There is no Apache, Ruby, PHP, MySQL, cPanel or any other panel installed, just the bare minimum that comes with a fresh installation.
Also the web server will host a single application and the database will run on the same machine.
From my knowledge the process of deploying a Rails application follows the following scenarios:
Installing Ruby
I already did this by using RVM using the Multi-User install process (simply because I have just the root user and it does it automatically). This seems to work fine aftewards but I do have some questions:
Would it make more sense to install Ruby directly and not through RVM (I'm thinking maybe in terms of efficiency - also RVM does a little bit of magic behind the scences modifying some bash_profile files in ways that I don't understand and this somehow seems invasive...)?
Would it make more sense to install as a separate user through RVM (can there any safety problems arise)?
Necessary gems
Now that Ruby is installed what would be the best initial set of gems to install along side it?
I installed just bundler, so that once I upload my application on the server I can run a bundle install command which will install in turn the required app gems.
Question - Should I install the rails gem before hand? Are there any other gems that need to be installed?
Web server
This is where it gets tricky for me. I'm trying to use apache and mod-passenger for deployment (they seem to be the most popular). So I installed the apache web server and the passenger gem and all the related dependencies (libraries mentioned by passenger).
Now, the problems arise. First thing is user related. How does Apache run? I mean under each user? If I installed it and (re)started it using the root user, will it permanently run under the root user? Is this a bad thing? If yes, should I create another user? If yes, how? In what groups should I put the new user in, what rights should he have (namely what folders should he have access to). How to start the apache in this case (under root, under that user, add a line somewhere in the configuration file, etc.)
Website configuration
Where to put the website configuration stuff? Is it OK to put it into apache.conf, or should I create a new file in sites-available? Or should I simply reuse the default file that is already present there? If a new user has been created at the previous step, what rights should he have in relation to the config files?
Also... where to eventually put the rails application? In what folder would it be best? Somewhere under home? Maybe under /var/www? I want to know how would this affect the rights of the apache process serving the app? (Generally I have problems while serving an app, it complains that it doesn't have rights on a specific folder. Also, using the new asset pipelines - which I don't fully understand - asset files are being created and they seem not to inherit the parent folder rights...)
Database
As database I'm using MySQL and installing it is pretty straightforward. The question that I have here is again user related. Should I use a special user for the database? How does MySQL actually manage users (are they internal, or are they the Linux users or ...?). Should the database user be the same as the "web user" from above? Or should it be a different one?
Assets
Here I get really lost. I really have troubles making the assets pipeline works. I've checked the railscasts episode and also the rails website tutorial and I do seem to theoretically understand the thing, yet I have problems in practice.
So the questions here would be - what commands should I run to precompile the assets? (Trying to run rake assets:precompile). Is it ok? What should I change in the production.rb file? How do the assets generated work in relation with the webuser or database users created above? I am personally getting a problem in this step namely the log files say that some css files are not accessible (for example I have jqplot library installed under the vendor/assets folder and its files cannot be accessed - should I add a manifest file here somehow?).
It would be really great if someone could point me towards a nice article, or resource that explains all this stuff. The main area which I'm having problems in is how does Apache, Passenger, Ruby, Rails and MySQL interact with a Linux user. How to properly set up the permissions for the Rails app folder? How does the assets pipeline affect this user permission stuff?
Thank you
Here's my way of deploying Rails:
Installing Ruby
I would not use RVM because it's very tricky to get it running properly in combination with stuff like cron jobs. Doable (with wrappers for example), but a bit of a hassle. If you don't need other Ruby versions on that machine, just install it from source yourself.
Gems
Just let Bundler work its magic. Remember to install with the flags --without test development --deployment. I wouldn't do that up front though. Just make sure you have bundler.
Web server
Using Passenger (with either Apache or Nginx) is a fine and easy choice. When you install Apache from apt, it will run in a special user.
Apache is configured correctly automatically on Ubuntu. It will start on reboot.
Website configuration
All configuration be in /etc/apache2. Place your virtual host configuration in /etc/apache2/sites-available and use a2ensite to enable it.
Put your app in /var/www, since that is the default location in Ubuntu. I usually make a deploy user.
Make sure that user can access your application by assigning your app to the www-data group.
Database
MySQL has its own user system. Log in as root user and create a new user with SQL: GRANT ALL ON 'application_production'.* TO 'deploy' IDENTIFIED BY 'some password';
Assets
Assets should be generated as the user owning the application. You should add any css and javascript files to production.rb. For example:
config.assets.precompile += %w(backend.css)
Conclusion
It helps to use a deploy tool like Capistrano. When you run capify, uncomment the appropriate line in the Capfile to get assets compilation. Here's mine:
ENV['RAILS_ENV'] = 'production'
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'deploy/assets'
load 'config/deploy'
require 'capistrano/ext/multistage'
require "bundler/capistrano"
require 'capistrano_colors'
This is just how I normally install my rails apps. I hope this will get you going. Recently I've written a gem for integrating Chef-solo with Capistrano, called capistrano-chef-solo. It's very alpha and might be a bit too complicated if you're just starting with deployment, but it might help you.

Subversion gem to track commit history in Ruby on rails app

Currently I'm doing research for a custom build deployment application on a unix system. I've also looked at Capistrano so don't worry ;). I'm looking for a gem that can give me the (subversion) commit stream of several projects. I'd like to run some tests with it to determine if it's possible/necessary to build a custom made deployment application.
Thanks
Take a look at the following URL :
http://www.oneofthewolves.com/2007/03/06/ruby-subversion-bindings-finally-some-documentation/

Resources