Hey guys,
I recently started with the 'Agile web development with Rails' book by pragmatic programmers after having some early experience with rails but wanting a more structured approach.
I'm happily following the book when they ask me to make a controller admin so I can edit the standard CRUD product model I already created. Accordin...
I have a rake task that calls functions like this:
namespace :blah do
task :hello_world => :environment do
logger.info("Hello World")
helloworld2
end
end
def helloworld2
logger.info("Hello Again, World")
end
I want the log output to a custom log, and I really don't want to have to pass a log reference every t...
I have a block like so:
begin
# some SQL request
rescue Mysql::Error => e
logputs "Mysql::Error occurred, retrying in 10s: #{e.message}"
sleep 10
retry
end
But when a "Lost connection to MySQL server" error occurred, this block was not able to catch it and retry (the MySQL server was restarted). Any idea how I ...
I'm working on a Rails app using attachment_ fu and Amazon S3 storage. Is it possible to make the :s3_ access (a part of the has_attachment options) conditional based on a user input when creating the object. I would like the user to be able if to select if the attachment is authenticated-read or public-read. Is this possible and how w...
This code in my view triggers an error:
<% remote_form_for(mymodel) do |f| %>
<%= f.error_messages %>
(mymodel is not an ActiveRecord object)
When I look at the error trace, I see this section which indicates that error_messages in the view translates into error_messages_for in the active_record_helper:
C:/Ruby18/lib/ruby/gems/1.8...
I mean, the mvc for cairngorm and the one in rails don't overlap their functionalities? I'm not sure I understand the need for cairngorm with the rails backend..
...
I was trying to understand this call:
deprecate :new_record?, :new?
which uses this deprecate method:
def deprecate(old_method, new_method)
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{old_method}(*args, &block)
warn "\#{self.class}##{old_method} is deprecated," +
"use \#{self.class}##{...
When finding web hosting for Rails apps, the hoster must have support for ruby on rails -- that is evident. What about hosting for Django? What support does the hoster need to provide? Python, or more than just Python?
This might seem like an obvious question, but I'm new to web development frameworks so I must ask :)
...
Hi. I have a Model Book with a virtual attribute for create a Editor from the Book form.
The code looks like:
class Book < ActiveRecord::Base
has_many :book_under_tags
has_many :tags, :through => :book_under_tags
has_one :editorial
has_many :written_by
has_many :authors, :through => :written_by
def editorial_string
self...
I'm fetching and manipulating XML from twitter and flickr in my rails app. The results appear on every page and the parsing is handled in the Application Controller with Hpricot and open-uri.
This is my first experiment with action caching and it doesn't seem to be working. I'm in dev mode using WEBRick. Everything appropriate is set to...
I have a form that I want to show a drop-down menu that shows a selection for the person's age. The range is from 18 to 99. How do I do it with the form select helper? Isn't it something like:
<%= f.select :age, ['18'..'99'] %>
...
On a Rails project, I'm using Sphinx together with Thinking Sphinx plugin. I index a table with an attribute :foo that is a float.
My desired behaviour when sorting for column :foo would be that nil values always appear at the end of the list, e.g.
id; foo (order foo desc)
-------
1; 5
2; 3
3; -4
4: -5
5: nil
6: nil
id; foo (order f...
Can anyone suggest some troubleshooting approaches for getting IRBRC running under Win32? The rails console is an awesome tool and I'm attempting to extend it with more functionality.
For instance, I would like the what_method gem to load automatically. The gem is installed but it does not load:
C:\...\trunk>ruby script\console
Loa...
Updated
Appears to be a precedence error and nothing to do with the question I originally asked. See discussion below.
Original question
Is it possible to use active record associations in callbacks? I've tested this code in the console and it works fine as long as it isn't in a callback. I'm trying to create callbacks that pull ...
I tried to update the specs on a gem that didn't have a .specification file.
1. cd {application_home_directory}
2. rake gems:refresh_specs
When I did, I received the recursive warning:
config.gem: Unpacked gem in vendor/gems has no specification file.
Run 'rake gems:refresh_specs' to fix this.
I've also tried this, which also fail...
I've noticed some ruby gems have .specification files and others don't.
If they're important, why are you not required (by whatever tool builds them) to provide one when you attempt to create your gem?
...
I like the idea of using submodules, but I am worried that I am leaving my code in someone else's hands. The main issue is that every time I deploy with capistrano, a new copy of the submodule is checked out since I am using:
set :git_enable_submodules, 1
So what happens if someone commits broken code? Then I app breaks on deploy. ...
environment.rb starts with this:
RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION
require File.join(File.dirname(__FILE__), 'boot')
Rails::Initializer.run do |config|
Does this mean environment.rb starts first and calls boot.rb?
...
Let's say in a Rails app you have some gems that you use in your app (we'll call them "primary gems") and you have vendored them for portability.
Let's say that those "primary gems" also require gems of their own - we'll call these "secondary gems".
When you are setting up your environment.rb, you have to say:
config.gem 'primary-gem...
Hello all,
I've just gotten started using BDD with RSpec/Cucumber/Webrat and Rails and I've run into some frustration trying to get my view spec to pass.
First of all, I am running Ruby 1.9.1p129 with Rails 2.3.2, RSpec and RSpec-Rails 1.2.6, Cucumber 0.3.11, and Webrat 0.4.4.
Here is the code relevant to my question
config/routes.rb...