Entries tagged with “Rails”.
Did you find what you wanted?
Tue 31 Jan 2012
Problem
You want to be able to use different gems/rails version for your application after installing the latest rails version, without having to use bundle exec.
Solution
You can use the named gemsets with rvm.
More instructions are here: http://beginrescueend.com/gemsets/basics/
so you can install two gemsets for example ruby-1.9.3-p0@rails3_0_11 and another with ruby-1.9.3-p0@rails3_2_1
you could then do :
rvm gemset create rails3_0_11 rails3_2_1
rvm 1.9.3-p0@rails3_0_11
gem install rails -v 3.0.11
rvm 1.9.3-p0@rails3_2_1
gem install rails -v 3.2.1
rvm gemset use rails3_0_11
bundle install
Tue 15 Nov 2011
Problem
You would like to use the fullcalendar jquery plugin to be able to display events in your rails application, but you also want to be able to set the eventSources dynamically depending on the path to your view, especially if your view contains a relationship as in the following example:
model_a/1/model_b (user/14/comments)
Solution
Change your eventSources to be something like the following and using the jQuery.ajaxSettings.url :
// a future calendar might have many sources.
eventSources: [{
url: jQuery.ajaxSettings.url,
color: 'orange',
textColor: 'black',
ignoreTimezone: false
}],
Thu 3 Nov 2011
Problem
You have two dates that you want to compare in your Rails application, which are both ActiveSupport::TimeWithZone.
Although they both look identical, when you are trying to compare them for equality (using ==), you get back false as a result.
Solution
These dates can have a difference in milliseconds that doesn’t normally get displayed. So first of all try to use to_f to see if they really have a difference.
If they do, then you would need to compare them by converting them to integers first as in :
date_a.to_i == date_b.to_i
and you should be getting back true
Mon 17 May 2010
Problem
You want to use find in Rails for a case sensitive search. For example in your authentication logic you have something to find the user to login as in:
u=User.find_by_login(‘username’)
If you don’t want to limit the available logins with case insensitive validation in the model, then the above code will not work if you have ‘Username’ and ‘username’ as available logins, as the find will only return one of them.
Solution
Change the find method to use the BINARY keyword in your database (only used with MySQL), as in the following:
u=User.find(:first, :conditions => ["BINARY login = ?", login])
Fri 26 Mar 2010
Problem
When you get the above error you cannot login to your application.
Solution
You will need to delete the cookies for the authentication, so in Firefox (Linux) go to Preferences, remove individual cookies for the specific domain.
Mon 15 Mar 2010
Problem
You want to deploy to a shared host (dreamhost) that has a later version of rails from the one you have developed your application.
You also have a later version installed in your development pc,and using rake rails:freeze:gems uses the latest one and not the one you want.
Solution
Use the following to freeze the specific version you want, and by using your gems you have installed:
rake rails:freeze:gems VERSION=2.3.2
Tue 8 Sep 2009
Problem
Your host (ie dreamhost) for deploying applications doesn’t have the gems you are using in your development.
Solution
After freezing your rails gems with rake rails:freeze:gems, freeze the rest of your gems, not with rake gems:freeze gem=GEM_NAME, as used in previous versions of rails, but with:
rake gems:unpack
Fri 4 Sep 2009
Posted by kosmas under ruby on rails
1 Comment
Problem
There was a warning about an XSS vulnerability in Ruby on Rails. More details can be found here.
Solution
Upgrade to the most recent (fixed) Rails version (2.3.4):
sudo gem install rails
Thu 8 Jan 2009
Problem
You have recently installed Mandriva 2009 and you want to install phusion passenger.
Solution
- First make sure that apache is installed. If it is not installed (default), do:
urpmi apache
On the selection question about the dependencies select option 1 (apache-prefork)
- Use the details from the phusion passenger website. ie:
Install passenger:
gem install passenger
- Run the passenger installation:
passenger-install-apache2-module
- If at the second stage of the installation the installer complains that GNU C++ compiler … not found, install the gnu c++ compiler, with:
urpmi gcc_c++
- Run the passenger installation (step 3) again. If at this stage the installer complains that Apache 2 development headers … not found, use:
urpmi apache-devel
- Run passenger installer (step 3), once more. Now everything should be ok and the apache 2 module will be installed when the installer finishes.
- Restart the Apache webserver, and you should be able to add your Rails application. Use the following to deploy your application in /somewhere/public:
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /somewhere/public
</VirtualHost>
Tue 25 Nov 2008
Posted by kosmas under ruby on rails
No Comments
Problem
Trying to use the assert_difference with Rails 2.1.0 produces errors if trying to use it with the syntax of another rails version.
Solution
The correct syntax for using assert_difference with rails 2.1.0 is:
def test_should_create_user
assert_difference(User, :count, 1) do
user = create_user
assert !user.new_record?, "#{user.errors.full_messages.to_sentence}"
end
end