Rails 4.1 is pretty nice release, but upgrade to this version may be painful. In this post I’ll try to help you.
First of all, you need to install the latest version of Rails. Here I’ll describe situation for 4.1.2, because I couldn’t bump app higher (and yes, upgrade from 4.1.1 to 4.1.2 may be painful too, welcome to Rails world).
Today I’d like to talk about one important (kind of) area of each RoR developer. This is testing. You may wonder, “Why the heck do I even need to write these stupid tests?”. Well, first of all, you may do it because your boss wants it. Or because all other rubyists write them. What do you mean, “I’m not satisfied?”. All right, how about making sure that your app don’t crush each time you commit new feature or fix a bug? Tests also help you to upgrade libs, install new Rails and other funny stuff, FYI. I know the company, who can’t upgrade to Rails 4, because it’s app don’t have tests.
Let me suppose, that you are satisfied by that and you started to write tests… Firstly with Rspec, because test-unit is not popular solution. And then you open Cucumber for yourself. And write more and more tests. And in one day you look in your terminal and you start to think that waiting 10 minutes until your features’d finish isn’t a good idea, because you can already drink few cups of tea or coffee and with such progress soon you’ll be able to watch a “Big bang theory”.
We meet different errors almost every day. Sometimes we get exceptions and we want to debug them to find the root of the problem. And better_errors helps us with that. It shows much nicer errors. It is like superman, just in programming area. And it is not just show stack trace to you, it also allows you to interact with your code and data using the console to get feedback immediately. It is nice, and I think, that you will get this feeling soon.
I would like to tell you about few gems, which would make your deployment life a little bit easier. Well, it worked for me.
Our first hero on the scene is rvm-capistrano. This hero is special, he prefers only capistrano №2. But time is changing and capistrano №3 is walking on streets of our computers, so, if you have seen it and even use it then you may select another hero: rvm1-capistrano3.
But I will talk about oldies here. What does this gem actually do? It brings integration between Rvm and capistrano. There are some discusses in the internet what to use, some people prefer rbenv, other use Rvm. Actually, rbenv is very small and it has very small code base, but it doesn’t have power of Rvm, so your choice should depend on your situation. But let me talk about hero, he is waiting to be presented!
Yep, this is another guide, which’ll help you (i hope!) to upgrade your app to the Rails 4. Before start, please make sure that you are running latest Rails 3 release, i think it is 3.2.17 nowadays. Yes, i’m sorry, Rails 2 guys, but this guide’ll not help a lot, you have a lot of work to do, sorry! :)
Thinking Sphinx is a library, which allows you use Sphinx – full text search server. But setup can be tricky, if you use PostgreSQL. In this post I will show you you how setup it.
First of all, make sure that you have installed Mysql. The best way to install it is just use homebrew:
$ brew install mysql==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.15.mavericks.bottle.tar.gz
######################################################################## 100.0%==> Pouring mysql-5.6.15.mavericks.bottle.tar.gz
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
I recommend you to copy and past commands from homebrew’s output after installation.
If you don’t want to use homebrew (but i strongly recommend to use homebrew), then you should install x64 MySQL server from official site. Make sure to use x64, you don’t want to get any weird errors (I guess that you use at least OS X 10.6).
Now you should install Sphinx. And it’s a tricky part. If you would install it without any flag or with just mysql support, you would get such weird errors:
$ rake ts:index
Generating configuration to /Users/serj/Projects/gearup/config/development.sphinx.conf
Sphinx 2.1.3-dev (r4319)Copyright (c) 2001-2013, Andrew Aksyonoff
Copyright (c) 2008-2013, Sphinx Technologies Inc (http://sphinxsearch.com)using config file '/Users/serj/Projects/gearup/config/development.sphinx.conf'...
indexing index 'service_core'...
ERROR: source'service_core_0': unknown type'pgsql'; skipping.
ERROR: index 'service_core': failed to configure some of the sources, will not index.
total 0 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 0 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
To avoid them you should instal sphinx with mysql and postgres support:
$ brew install sphinx --mysql --pgsql
==> Downloading http://sphinxsearch.com/files/sphinx-2.1.3-release.tar.gz
Already downloaded: /Library/Caches/Homebrew/sphinx-2.1.3.tar.gz
==> Downloading http://snowball.tartarus.org/dist/libstemmer_c.tgz
Already downloaded: /Library/Caches/Homebrew/sphinx--stemmer-c.tgz
==> ./configure --prefix=/usr/local/Cellar/sphinx/2.1.3 --localstatedir=/usr/local/var --with-libstemmer --with-mysql --with-pgsql
==> make install==> Caveats
Sphinx has been compiled with libstemmer support.
Sphinx depends on either MySQL or PostreSQL as a datasource.
You can install these with Homebrew with:
brew install mysql
For MySQL server.
brew install mysql-connector-c
For MySQL client libraries only.
brew install postgresql
For PostgreSQL server.
We don't install these for you when you install this formula, aswe don't know which datasource you intend to use.
🍺 /usr/local/Cellar/sphinx/2.1.3: 16 files, 18M, built in 17 seconds
Have you ever met problems with integrating the Jquery Token Input and the acts_as_taggable_on? Or are you gonna to implement these things together? Hold on! This article’ll help you: I’ll show you step by step how to do that with Rails 3.2.
Devise is a great gem! It really helps you, taking all authentication jobs away from you. However, upgrading Devise up to version 3.x can be a little bit tricky. In this post I’ll show you how to do that.
First of all, update your gem via bundle update OR specify version in your Gemfile:
And run bundle install.
Since devise 3.1 platformatec announced few security improvements. One of them is secret_key. To add it open devise config and add:
# The secret key used by Devise. Devise uses this key to generate# random tokens. Changing this key will render invalid all existing# confirmation, reset password and unlock tokens in the database.config.secret_key='2710f15f11771d6692a3015d7e3dba2cb05539c1f72i6u345df5433hg535kj5x56v6er56if2566c63c2ad670d6859e536b40d87e6543b115609f0464bdd99502abbe241c4'
Of course, you should use your own secret key, so change my example to be more secure.
If you have ever generated devise’s views, then you should change it’s mailers to use @token instead of @resource.*_token:
If you love Sublime Text 2 as I do then you probably would like to change default git editor (which is Vim nowadays). I suppose that you have installed Sublime text.
First of all, you should install subl shortcut. To do that open your shell and print (if you already have ~/bin directory, then just use the last line of my code):
$ cd ~
$ mkdir bin
$ ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Now restart your shell and try that:
$ subl -h
Sublime Text 2 Build 2221
Usage: subl [arguments][files] edit the given files
or: subl [arguments][directories] open the given directories
or: subl [arguments] - edit stdin
--project <project>: Load the given project
--command <command>: Run the given command -n or --new-window: Open a new window
-a or --add: Add folders to the current window
-w or --wait: Wait for the files to be closed before returning
-b or --background: Don't activate the application
-s or --stay: Keep the application activated after closing the file
-h or --help: Show help(this message) and exit -v or --version: Show version and exit--wait is implied if reading from stdin. Use --stay to not switch back
to the terminal when a file is closed (only relevant if waiting for a file).
Filenames may be given a :line or :line:column suffix to open at a specific
If you have the same output, then everything works great. Otherwise you should add ~/bin to your $PATH. To do that open your ~.bash_profile and append these lines to the end of the file:
And I think that you should restart your shell again.
Finally, to set up sublime as default editor just print in your shell that: