Yes, I had no idea of what that was.
I found a post by Mislav Marohnić where he explains it very well, enjoy :)
http://mislav.uniqpath.com/2013/01/understanding-binstubs/
Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts
Saturday, October 12, 2013
Friday, October 11, 2013
Setting up a Rails environment with RVM
Hi, happy? I hope so :)
So here I'll show you how to setup a Rails environment using RVM, if you are a Windows user, I'm sorry, RVM is not for you but you can do it using a VM.
We are going to install RVM that stands for Ruby Version Manager and create some Gemsets with different Rails, Ruby and Gem versions.
You can also append some options like --rails, --ruby or specify the version like --ruby=1.9.3.
After the installation there will be a folder .rvm on your home directory, that's where all the magic will happen. If something goes wrong in the future you can remove that folder and install again but all your Gemsets, Gems and Rubies will be gone as well, be careful.
When the installtion is over it will automatically update your .bash_profile adding this:
source $HOME/.rvm/scripts/rvm
Which will make your RVM recognizable on your terminal as a function, otherwise it won't work. If for some reason it doesn't happen, you can add it by yourself like:
echo "source $HOME/.rvm/scripts/rvm" >> ~/.bash_profile
When that's done you must reload your dotfile so the new line take effect:
. ~/.bash_profile
Or you can close and reopen your terminal :)
OK, now you have RVM working as a function and the next step is to check your OS requirements for it to work.
rvm requirements
In my case, using Manjaro, it has no requirements but when it does it will start downloading and in some cases it must be run as sudo.
To check what is available for you to use like ruby, jruby, macruby, etc:
rvm list known
All those options are available for you to install like this:
rvm install your_option_goes_here
So let's install Ruby 1.9.3. As you can see it has 1.9.3[-p448]
rvm install 1.9.3-p448
This step will download, extract, configure and compile so it may take some time depending on your CPU and connection and if something goes wrong during one of these steps, be calm and read carefully the messages given, they are really helpful.
When Ruby is installed you can check it:
ruby -v
Which will return, in case you installed 1.9.3-p488, something like this:
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
You can install any Ruby version you wish following the above step and to use it you do this:
rvm use 1.9.3
Let's suppose you also have Ruby 2.0.0 installed, to use it:
rvm use 2.0.0
You can also reinstall it. That will happen in case your OS doesn't have a required library, e.g.: libyaml and you have already installed Ruby
rvm reinstall RUBY_VERSION
And voilà
That's it about installing Ruby.
Now let's work with Gemsets. This is how you'll organize all your Gems so you don't make a mess.
First you need to check all the available Gemsets
rvm gemset list
It will list a (default) and global Gemsets. If you do not specify the Gemset where you want to install a gem, it will be installed in the default Gemset.
The global Gemset has some Gems that are used frequently like bundler, json, rake, rdoc, etc, to have a complete list use gem list.
Now you'll create a Gemset called my_project and we'll install rails 3.2.14
rvm gemset create my_project
You can check it using rvm gemset list
IMPORTANT: For each and every Ruby version there will be a different Gemset list. To test it, change your Ruby version (rvm use 1.9.3 or whatever) and check it's Gemset list.
To use that Gemset
rvm use 1.9.3@my_project
Now install your gems
gem install rails -v 3.2.14
When the process is over, you can check it using
rails -v
And that Rails version will be available only when using that Gemset.
Obviously you can create lots and lots of Gemsets and each with lots and lots of Gems that will not conflict with each other.
Now let's suppose you'll create a project using Rails 4.0.0
You'll create a new Gemset for that project
rvm gemset create my_new_project
rvm use 1.9.3@my_new_project
gem install rails
Done, you have now two Gemsets (my_project and my_new_project) each with a different Rails version and you can install all other Gems required for your project.
If you need to remove a Gemset, you must be using it (rvm RUBY_VERSION@GEMSET_NAME) and do this:
rvm gemset delete
You can rename your Gemset:
rvm gemset rename current_name new_name
To make my life easier I have created some aliases on my .bash_profile so I don't have to type rvm RUBY_VERSION@GEMSET_NAME.
That's it, if you know a way I can improve it, please let me know it.
I wish you the best.
Today, be calm when you would be nervous
Labels:
gems,
gemset,
install rvm,
rails,
rails environment,
ruby,
rvm,
rvm install
Sunday, September 8, 2013
Making spree 2.0.3 show your gateway error messages
Hi there, happy?
I have developed an active merchant gateway, called 2Pay and I configured my Spree to use it.
It was working great until I got warned that when something goes wrong with the client's credit card, spree is always showing a default error message.
Well, that is terrible because the client will have no idea of what is going on among all possibilities.
PAUSE: I have this on StackOverflow if you feel more comfortable there :)
I had to do one thing, check the spree_core source code using
Searching a bit more I found that the order.rb model rescue block wasn't adding the error to the errors hash.
Anyway, these are the two files you need to override and to do that you need to create checkout_controller.rb as checkout_controller_decorator.rb on /controller and the order.rb as order_decorator.rb on /model.
I know the paths are obvious but some user on #spree channel told me to save them on different folder and that was making me more confused.
I really hope it helps you my friend.
Now, be a nice person and say something nice to who's with you :)
I have developed an active merchant gateway, called 2Pay and I configured my Spree to use it.
It was working great until I got warned that when something goes wrong with the client's credit card, spree is always showing a default error message.
Well, that is terrible because the client will have no idea of what is going on among all possibilities.
PAUSE: I have this on StackOverflow if you feel more comfortable there :)
I had to do one thing, check the spree_core source code using
bundle open spree_coreSo I noticed how the checkout_controller was calling a default message when something goes wrong with the Gateway object so I had to update it but it didn't work 100%.
Searching a bit more I found that the order.rb model rescue block wasn't adding the error to the errors hash.
Anyway, these are the two files you need to override and to do that you need to create checkout_controller.rb as checkout_controller_decorator.rb on /controller and the order.rb as order_decorator.rb on /model.
I know the paths are obvious but some user on #spree channel told me to save them on different folder and that was making me more confused.
I really hope it helps you my friend.
Now, be a nice person and say something nice to who's with you :)
Labels:
gateway,
gateway error,
override,
rails,
ruby,
spree,
spree 2.0.3,
spree error messages,
spree gateway error,
spree gateway error messages,
spree-commerce,
spree-ecommerce
Location:
Cássia - Minas Gerais, Brazil
Tuesday, June 11, 2013
Kaprekar number
Hi there reader, happy?
Today I was introduced to the Kaprekar number and decided to check if a given number is a kaprekar one.
Here is what I got:
To make it run simply:
Now, be a good person a hug the person next to you =)
Today I was introduced to the Kaprekar number and decided to check if a given number is a kaprekar one.
Here is what I got:
To make it run simply:
ruby kaprekar.rb n
Now, be a good person a hug the person next to you =)
Tuesday, February 19, 2013
Rails errors with Foundation style with simple_form
I just made my error messages use Foundation styles (http://foundation.zurb.com/docs/forms.php, scroll until Error States)
I edited the simple_form initializer:
Now you have cool error/alert/whatever messages.
Be happy
I edited the simple_form initializer:
Now you have cool error/alert/whatever messages.
Be happy
Labels:
css,
css foundation,
forms,
foundation,
html,
rails,
ruby,
simple_form
Friday, February 15, 2013
RSpec or UnitTest
I asked that myself 5 minutes ago and wasted 3 searching and guess what, 50% votes for RSpec and the other half to UnitTest. So, based on this "in depth" research, I came up with the solution.
I doesn't matter at all, choose that one that reads cleaner. It's like asking: "What is the best editor?"
I doesn't matter at all, choose that one that reads cleaner. It's like asking: "What is the best editor?"
Monday, January 28, 2013
Testing different database connections
Hello world!
I had to test some database connections from inside my application.
The user fill a form with the required information but before saving it to my PostgreSQL instance I had to check if everything is OK.
I was trying to use my model like this:
And guess what, as expected it replaces my application connection.
The solution is pretty simple, use the adapter class like:
The reason for this code be inside a bedin/rescue is that if anything is wrong with the connection data it will return 500 Internal Server Error
Problem solved.
Labels:
adapter,
connections,
database,
mysql,
postgresql,
rails,
ruby
Monday, October 22, 2012
Ruby - Installing gem eventmachine
Hi fellas!
Trying this:
Returned me this:
The solution is installing the build-essential package:
Problem solved!
Trying this:
$ gem install eventmachine
Returned me this:
make
compiling ssl.cpp
make: g++: Command not found
make: *** [ssl.o] Error 127
The solution is installing the build-essential package:
$ sudo apt-get install build-essential
Problem solved!
Friday, October 19, 2012
Ruby - Installing gem debugger
Hi fellas!
Tryin this:
Returned this:
Reading the error I tried this:
Problem solved.
Adios!
Tryin this:
$ gem install debugger
Returned this:
checking for vm_core.h... no
checking for vm_core.h... no
Makefile creation failed
**************************************************************************
No source for ruby-1.9.3-p286 provided with debugger-ruby_core_source gem.
**************************************************************************
Reading the error I tried this:
$ gem install debugger -- --with-ruby-include=/home/$(echo $USER)/.rvm/src/ruby-$(ruby -v | cut -d" " -f2)
Problem solved.
Adios!
Monday, October 8, 2012
Ruby - Error fetching data
Hi fellas.
I was trying to install mysql gem and got this message:
That's weird isn't it? Couldn't find mysql and a possible alternative is mysql?
Not thinking too much I remembered I had a proxy change on my system. Set it to none and same problem.
Googling a bit I found this: --no-http-proxy
Problem solved and lesson learned. The gem install remembers my last proxy configuration and stick with it regardless of its availability.
Adios!
I was trying to install mysql gem and got this message:
WARNING: Error fetching data: SocketError: getaddrinfo: Name or service not known (http://rubygems.org/latest_specs.4.8.gz)
ERROR: Could not find a valid gem 'mysql' (>= 0) in any repository
ERROR: Possible alternatives: mysql
That's weird isn't it? Couldn't find mysql and a possible alternative is mysql?
Not thinking too much I remembered I had a proxy change on my system. Set it to none and same problem.
Googling a bit I found this: --no-http-proxy
$ gem install mysql --no-http-proxy
Problem solved and lesson learned. The gem install remembers my last proxy configuration and stick with it regardless of its availability.
Adios!
Monday, October 1, 2012
Ruby - Can't Install Curb
Hi fellas!
As suggested, I tried to install curb but no success!
The solution?
Install this: libcurl4-gnutls-dev and guess what, problem SOLVED!
On Fedora you do:
Adios!
When trying to install Curb(0.7.15) with native extensions I got this message:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/daniel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for curl-config... no
checking for main() in -lcurl... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/daniel/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-curl-dir
--without-curl-dir
--with-curl-include
--without-curl-include=${curl-dir}/include
--with-curl-lib
--without-curl-lib=${curl-dir}/lib
--with-curllib
--without-curllib
extconf.rb:23:in `<main>': Can't find libcurl or curl/curl.h (RuntimeError)
Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
options to extconf.
Gem files will remain installed in /home/daniel/.rvm/gems/ruby-1.9.3-p194/gems/curb-0.7.15 for inspection.
Results logged to /home/daniel/.rvm/gems/ruby-1.9.3-p194/gems/curb-0.7.15/ext/gem_make.out
An error occurred while installing curb (0.7.15), and Bundler cannot continue.
Make sure that `gem install curb -v '0.7.15'` succeeds before bundling.
As suggested, I tried to install curb but no success!
The solution?
Install this: libcurl4-gnutls-dev and guess what, problem SOLVED!
On Fedora you do:
$ yum install libcurl -devel.(64 or 32 bit version)
Adios!
Subscribe to:
Posts (Atom)