Ruby on Rails is an open-source web development framework written in Ruby. Ruby on Rails follows the principle of convention over configuration, freeing you from having to re-invent things to stay productive. Ruby on Rails 4.0 is now available.
13
votes
1answer
4k views
Ignoring timezones altogether in Rails and PostgreSQL
I'm dealing with dates and times in Rails and Postgres and running into this issue:
The database is in UTC.
The user sets a time-zone of choice in the Rails app, but it's only to be used when ...
156
votes
9answers
61k views
Best way to load module/class from lib folder in Rails 3?
Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore,
what would be the best way to load them?
From github:
A few changes were done in this commit:
Do not ...
155
votes
15answers
46k views
Repairing Postgresql after upgrading to OSX 10.7 Lion
I recently upgraded to OSX 10.7, at which point my rails installation completely borked when trying to connect to the psql server. When I do it from the command line using
psql -U postgres
it ...
62
votes
27answers
46k views
rails error, couldn't parse YAML
After updating the gems I've got this:
/home/megas/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/psych.rb:148:in `parse': couldn't parse YAML at line 182 column 9 (Psych::SyntaxError)
from ...
128
votes
8answers
28k views
Undefined method 'task' using Rake 0.9.0
I just updated Rake to the latest version (0.9.0.beta.4) and the rake command ends up with the following error message:
rake aborted!
undefined method `task' for ...
39
votes
6answers
52k views
Facebook how to check if user has liked page and show content?
I am trying to create a Facebook iFrame app. The app should first show an image and if the user likes the page, he will get access to some content.
I use RoR, therefore I can't use the Facebook PhP ...
234
votes
9answers
24k views
How to disable logging of asset pipeline (sprockets) messages in Rails 3.1?
Sprockets tends to be quite verbose in the (dev) log by default under Rails 3.1 (RC1):
Started GET "/assets/application.css" for 127.0.0.1 at 2011-06-10 17:30:45 -0400
Compiled ...
80
votes
7answers
24k views
Remove ActiveRecord in Rails 3
Now that Rails 3 beta is out, I thought I'd have a look at rewriting an app I have just started work on in Rails 3 beta, both to get a feel for it and get a bit of a head-start. The app uses MongoDB ...
41
votes
3answers
22k views
Build vs new in Rails 3
In the Rails 3 docs, the build method for associations is described as being the same as the new method, but with the automatic assignment of the foreign key. Straight from the docs:
...
212
votes
25answers
43k views
No route matches “/users/sign_out” devise rails 3
I've installed devise on my app and applied the following in my application.html.erb file:
<div id="user_nav">
<% if user_signed_in? %>
Signed in as <%= current_user.email ...
77
votes
8answers
23k views
Best way to add page specific javascript in a Rails 3 app?
Rails 3 has some unobtrusive javascript which is pretty cool.
But I was wondering what the best way is to include additional JS for a particular page.
For example, where I might have previously ...
94
votes
5answers
36k views
How to fix the uninitialized constant Rake::DSL problem on Heroku?
I am getting errors similar to the ones in these questions, except mine are occuring on Heroku:
2011-05-30T09:03:29+00:00 heroku[worker.1]: Starting process with command: `rake jobs:work`
...
106
votes
8answers
42k views
Can't find the 'libpq-fe.h header when trying to install pg gem on ubuntu
I am using rails 3.1 pre version. I like to use PostgreSQL but the problem is installing the pg gem. It gives me the following error:
demonchand@system-001:~/exercise/personal/pro$ gem install pg
...
58
votes
6answers
27k views
Rails - Could not find a JavaScript runtime?
I created a new Rails project using rails 3.1.0.rc4 on my local machine but when I try to start the server I get:
Could not find a JavaScript runtime. See here for a list of available runtimes. ...
42
votes
3answers
15k views
Devise form within a different controller
I am using a devise gem for sign_in/sign_out procedures.
I generated views files from devise, using rails g devise views
I saw there was a devise/sessions/new.html.erb file which contained a form ...
25
votes
3answers
17k views
Rails 3 devise, current_user is not accessible in a Model?
in my project.rb model, I'm trying to create a scope with a dynamic variable:
scope :instanceprojects, lambda {
where("projects.instance_id = ?", current_user.instance_id)
}
I get the ...
23
votes
5answers
17k views
Setting session timeout in Rails 3
This seems simple: I am trying to get my rails Active Record session to timeout after 2 minutes. So after two minutes I want my users to have to re-login.
I'm just running rails server (i.e. ...
3
votes
2answers
3k views
cannot load such file — script/rails : Getting this error while remote debugging through RubyMine
I am getting following error while remote debugging through RubyMine IDE.
$ bundle exec rdebug-ide --port 1234 -- script/rails server
Fast Debugger (ruby-debug-ide 0.4.9) listens on :1234
...
74
votes
5answers
13k views
Rails 3.1: Engine vs. Mountable App
Can someone help me understand the differences between a Rails Engine and a Mountable app? In Rails 3.1, you can create either one with the "rails new plugin ___" command.
rails plugin new forum ...
59
votes
6answers
14k views
Rails 3: “field-with-errors” wrapper changes the page appearance. How to avoid this?
Email field:
<label for="job_client_email">Email: </label>
<input type="email" name="job[client_email]" id="job_client_email">
looks like this:
But, if the email validation ...
9
votes
6answers
5k views
Extending controllers of a Rails 3 Engine in the main app
I am using a Rails engine as a gem in my app. The engine has PostsController with a number of methods and I would like to extend the controller logic in my main app, e.g. to add some methods. If I ...
31
votes
6answers
13k views
ActiveRecord OR query
This is an embarrassing noob question, but...
How do you do an OR query in Rails 3 ActiveRecord. All the examples I find just have AND queries.
Edit: without using a SQL string!
114
votes
2answers
42k views
Rails 3 where condition using NOT NULL
Using the rails 3 style how would I write the opposite of:
Foo.includes(:bar).where(:bars=>{:id=>nil})
I want to find where id is NOT null. I tried:
...
49
votes
4answers
26k views
Best Ruby on Rails WebSocket tool [closed]
I started project in Rails 3 and I need to add notifications(like Facebook one). Best way would be using WebSocket for support devices like iPad, but I can't find any good tools to easy implement it ...
30
votes
3answers
6k views
STI, one controller
I'm new to rails and I'm kind of stuck with this design problem, that might be easy to solve, but I don't get anywhere:
I have two different kinds of advertisements: highlights and bargains. Both of ...
36
votes
10answers
12k views
Ruby on Rails 3: Streaming data through Rails to client
I am working on a Ruby on Rails app that communicates with RackSpace cloudfiles (similar to Amazon S3 but lacking some features).
Due to the lack of the availability of per-object access permissions ...
24
votes
6answers
20k views
rails 3 - link_to to destroy not working
I am trying to create a destroy link to my users controller, I am also using devise.
Here is my code -
View
<%= link_to 'Delete User?', child, :confirm => "Are you sure you want to delete ...
10
votes
2answers
10k views
What is the replacement for ActionController::Base.relative_url_root?
I am porting a 2.x rails app to rails3; we'll call it foo-app. Foo-app is one section of a larger rails app and lives at main_rails_app.com/foo-app. Previously we just set up the following in our ...
9
votes
4answers
3k views
Clarification on how to use “thumbs_up” voting gem with Rails 3
I am attempting to implement the thumbs_up voting gem on a Rails 3 app, however the instructions are unclear on the actual implementation. After requiring the gem [gem 'thumbs_up'] and after creating ...
12
votes
3answers
11k views
Alias for column names in Rails
In my database has column names such as 'delete' or 'listen-control' and so on. These cannot be changed, so I would like to alias the names so as to avoid problems in my application.
I found the ...
116
votes
6answers
89k views
Rails 3.1 and Image Assets
Think I'm going mad on this one.
I am playing with rails 3.1 and I am having issues with images.
I have put all my images for my admin theme in the assets folder within a folder called admin. then
...
51
votes
4answers
11k views
Disable Rails 3.1 SQL logging
Is there a way to disable SQL query logging when I'm executing commands in the console? Ideally, it would be great if I can just disable it and re-enable it with a command in the console.
I'm trying ...
35
votes
2answers
11k views
Rails 3 SSL routing redirects from https to http
This question relates to this SO question and answer (rails-3-ssl-deprecation
) where its suggested to handle ssl in rails 3 using routes.rb and routes like:
resources :sessions, :constraints => ...
30
votes
6answers
17k views
f.error_messages in Rails 3.0
Rails 3.0 deprecated f.error_messages and now requires a plugin to work correctly - I however want to learn how to display error messages the (new) native way. I am following the getting started ...
24
votes
4answers
20k views
Timezone with rails 3
I have pretty common issue but for some reason i have tried all the suggestions on the web and none seem to work.
I have set the Timezone in config to 'EST'
config.time_zone = 'Eastern Time (US ...
34
votes
7answers
5k views
How do I write a Rails 3.1 engine controller test in rspec?
I have written a Rails 3.1 engine with the namespace Posts. Hence, my controllers are found in app/controllers/posts/, my models in app/models/posts, etc. I can test the models just fine. The spec for ...
41
votes
10answers
4k views
do..end vs curly braces for blocks in Ruby
I have a coworker who is actively trying to convince me that I should not use do..end and instead use curly braces for defining multiline blocks in Ruby.
I'm firmly in the camp of only using curly ...
22
votes
9answers
16k views
Heroku push rejected, no Cedar-supported app detected
Rails app, Rails 3.1.3
git init
git remote add heroku <my heroku repo>
git add .
git commit -a -m "First commit"
git push heroku master
Got:
Counting objects: 102, done.
Delta compression ...
17
votes
4answers
16k views
Submit form in rails 3 in an ajax way (with jQuery)
I am a beginner in rails and jQuery. I have two separate forms in one page and I want to submit them separately in ajax way (with jQuery). This is how far I got. Can anybody add or fix this code to ...
39
votes
7answers
17k views
Rails 3: Get Random Record
So, I've found several examples for finding a random record in Rails 2 -- the preferred method seems to be:
Thing.find :first, :offset => rand(Thing.count)
Being something of a newbie I'm not ...
14
votes
5answers
17k views
Where to put Global variables in Rails 3
I used to put Global variables in environment.rb with my Rails 2.3.8 application such as:
MAX_ALLOWD_ITEMS = 6
It doesn't seem to work in Rails 3. I tried putting it in application.rb and that ...
12
votes
2answers
5k views
How to configure Log4r with Rails 3.0.x?
I tried configuring log4r with Rails 3.0.4 based on this article: http://www.dansketcher.com/2007/06/16/integrating-log4r-and-ruby-on-rails/
...
341
votes
6answers
86k views
How can I rename a database column in a Rails migration?
I wrongly named a column hased_password instead of hashed_password.
How can I use a migration to rename this column?
28
votes
6answers
12k views
Connecting Rails 3.1 with Multiple Databases
At ShowNearby we have been doing a very big migration to RoR 3.1 from PHP and we are facing several problems that may be some of you have solved before.
We have big amounts of data and we decided to ...
18
votes
1answer
8k views
simple hit counter for page views in rails
I've found several solutions for this problem, for example railstat from this post:
Page views in Rails
I have a bunch of articles and reviews which I would like a hit counter filtered by unique ...
45
votes
2answers
28k views
How to do a LIKE query in Arel and Rails 3?
I want to do something like:
SELECT * FROM USER WHERE NAME LIKE '%Smith%';
My attempt in Arel:
# params[:query] = 'Smith'
User.where("name like '%?%'", params[:query]).to_sql
However, this ...
33
votes
10answers
10k views
Ruby on Rails 3 - Reload lib directory for each request
I'm creating a new engine for a rails 3 application. As you can guess, this engine is in the lib directory of my application.
However, i have some problems developing it. Indeed, I need to restart my ...
29
votes
5answers
7k views
Share database between 2 apps in Heroku
I want to access the database of an app from another Heroku app. Is that possible in the shared database?
Thanks
43
votes
6answers
30k views
How make a HTTP GET request using Ruby on Rails?
I would like to take information from another website. Therefore (maybe) I should make a request to that website (in my case a HTTP GET request) and receive the response.
How can I make this in Ruby ...
45
votes
4answers
11k views
Stubbing authentication in request spec
When writing a request spec, how do you set sessions and/or stub controller methods?
I'm trying to stub out authentication in my integration tests - rspec/requests
Here's an example of a test
...