ruby-on-rails

Rails can't find the generator class

I have some code that is using SyncEnumerator. As you can see here, SyncEnumerator requires generator.rb. To include this, the developer of this plugin has require 'generator'. This worked on my previous Rails installation but is not working since I upgraded OS X and reinstalled Rails. Now when I try to install my gems, I get: Macint...

Using a duration field in a Rails model

I'm looking for the best way to use a duration field in a Rails model. I would like the format to be HH:MM:SS (ex: 01:30:23). The database in use is sqlite locally and Postgres in production. I would also like to work with this field so I can take a look at all of the objects in the field and come up with the total time of all objec...

Comment notification to users in rails?

Hi, my webapp has registered users and it has articles, blog posts, gossips too. For all these resources I've a polymorphic Comment model which is listed below. id content commentable_id commentable_type user_id created_at updated_at 1 Frist comment 2 Article 1 .... 2 Second comment 3...

Missing record in Rails Testing

I'm trying to test Rails' Javascript with Cucumber/celerity and factorygirl. The stack itself works, but database is going crazy. I'm running mongrel on 3001 port (tried in both cucumber and test environments) and access it from cucumber via celerity. One of my tests looks following: create item 1 item exists do smth with item it w...

Are there any cases in which Rails overwrites controller instance variables on render :partial?

Are there any cases in which Rails overwrites controller instance variables on a render :partial call performed in a template? For example, let's say we have: controller def my_action @widget = Widget.find(params[:id]) end view my_action.html.erb Hi there. <%= render :partial => 'my_helper' %> That's it, that's all. view _my_he...

Ruby on Rails: What Reporting and/or Charting Tools Are Available?

I'm just starting out with Ruby/Rails and am wondering what Rails developers use to provide reports and/or charts on Rails sites. In ASP.NET I use the tools from DevExpress but I don't know enough about the Rails ecosystem to know what is available. Any insight would be appreciated. ...

What is a better way to check for a nil object before calling a method on it?

I have this method call I have to use... financial_document.assets.length But financial_document.assets could be nil. I could use... financial_document.assets.nil? ? '0' : financial_document.assets.length Is there a less repetitive way to do that? ...

Constricting find conditions based upon runtime contexts

Wow crazy title! But here's the problem. In efforts to dry up my school website management system application, I've made a module of my application (FileSet) restful and placed it in one place. Previously FileSet was used in the general website system, and also in a kids learning area system. They both behaved exactly the same except for...

Star rating in AJAX with Ruby On Rails

I think that acts_as_rateable seems to be quite obsolete and doesn't support AJAX. I'm looking for a simple "5 star" rating system: is there any plugin or tutorial that can help? ...

In Rails how can I implement a HTML select menu using an Array of Strings?

I have a FinancialDocument#document_type model attribute. I'd like to let the user select the document type from an HTML select menu populated by an Array of Strings... doctypes = [ 'Invoice', 'Packing slip', 'Other' ] For each option, the displayed label and returned value would be identical. I looked at the select and collection_se...

How can you configure Rails to use blueprint-css instead of the default scaffolding css?

What changes do you need to make to a Rails project to configure blueprintcss as the default stylesheet to be used when you generate scaffolding instead of scaffold.css? ...

Can modules add relationships and named_scopes to Rails models...

How do I create a module that when included in a model will automatically add some relationships and named_scopes? Here's what I've got right now: module Resource has_many(:permissions) named_scope( :acl_check, lambda do |user_id, method| { :include => :permission, :conditions => [ ["permissions.user_id=...

Text search options for a Web app?

I'm going to be implementing a Web app using Rails with MySQL running on a small CentOS VPS. (Small server, limited user base to start out.) It's going to store a lot of text, sort of like a blog. I'd like to offer strong search options -- parens, AND, OR, exact phrase. The other piece of it is that the data is private, so using Google ...

nomethoderror for rack::utils::escape

I'm new to rails so I apologize for my ignorance. I'm setting a constant in a class outside of a method: PARAM = { #... => ... 'field' => escape('somethingwith/slashes') } and get a NoMethodError: undefined method 'escape' I tried Rack::Utils::escape and Rack::Utils.escape instead, but both don't work. Thanks in advance....

Ruby on rails scaffolding in Netbeans 6.5

I am playing with the scaffold feature of rails in Netbeans 6.5. Right click->Generate gives me a menu that allows me to create the scaffold but asks for "attribute pairs". I have some tables with quite a few columns and would rather have the scaffolded pages include them all instead of specifying each one individually. Does anyone know...

Why isn't Passenger respecting my custom log format?

I need to change the log format of my rails app. I put this file in lib directory and required it in development.rb env file. require 'hodel_3000_compliant_logger' config.logger = Hodel3000CompliantLogger.new(config.log_path) and I should get the output of the development.log file as follows: Jun 28 03:05:13 millisami-notebook rai...

How do you override :set_initial_state from AASM when testing with Factory Girl factories?

Update Answered below. In case the linked site disappears, you can use mocha to stub the initial state and prevent overwriting as in ... require 'mocha' class OrderTest < ActiveSupport::TestCase def setup Order.any_instance.stubs(:set_initial_state) @order = Factory(:order, :state => "other_state") end ... end Origina...

Can I narrow down the type of classes retrieved by a Polymorphic relationship in Rails?

I have a polymorphic relationship in Rails, but in one particular instance of use, I'd only like to retrieve records for a specific class. What's the best approach to do this? ...

Inheritance and Polymorphism conflicting in ruby on rails

Hi, I have an issue with Ruby on Rails. I have several model classes that inherit from the same class in order to have some generic behaviour. The parent class is called CachedElement. One of the child is called Outcome. I want an other model, called Flow to belong to any child of CachedElement. Hence Flow has a polymorphic attributes...

Objects and Relations in Ruby on Rails

I'm attempting to create a simple web application for some personal development, but I've run into an obstacle, which I'm hoping others will find trivial. I have working classes created, but I'm not sure how define their relationships, or whether their models are even appropriate. For the sake of argument, I have the following classes a...