ruby-on-rails

error while trying to push database to heroku

I am trying to do a $heroku db:push this is the error I get C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/utils.rb:138:in `union': can't convert Array into String (TypeError) from C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.2.1/lib/rack/utils.rb:138 from C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in ...

Using dynamic finders to specify NOT NULL

I very often want to use dynamic finders to specify NOT NULL. So… this works: Widget.find_all_by_color('blue') this works: Widget.find_all_by_color(nil) But how can I do SELECT * FROM `widgets` WHERE `color` IS NOT NULL; ? ...

uninitialized constant on class from ruby gem

Hello, I am trying to implement a gem called stanfordparser which can be found here: http://stanfordparser.rubyforge.org/ It is a ruby wrapper for a java natural language parser I am developing in netbeans using ruby on rails / jruby on a windows 7 machine. My web app works fine otherwise, but when I try to add the parser wrapper it br...

Question about update_all in Ruby

I created an array using this statement.. users_who_promoted = @organization.card_signups.select {|c| c.credit_status == true } but when I do this : users_who_promoted.update_all("credit_status = false") I get a big error : NoMethodError: undefined method `update_all' for #<Array:0x32377bc> from (irb):25 Why is this? ...

Ruby on Rails: remove element from array by id

Is there some sort of short hand for @notifications = Notification.find(:all, :conditions => ['expires_at > ?', Time.now]) notif = Notification.find(:all, cookie[0].to_i) @notifications.delete(notif[0]) if not notif.empty? cookie is an id of a notification stored into cookies. this is in an iteration, that removes notifications ...

What's the correct way to handle optional time information in Rails?

I'm working on a Rails application that allows users to define Tasks, which require a due_date. The due_date may or may not include a time. The way we're handling this right now feels like a hack. due_dates default to 12:00 AM, and in that case we don't display a time. The DateTime object doesn't allow for empty Time values as far as I ...

How do I pass a var from one model's method to another?

Here is my one model.. CardSignup.rb def credit_status_on_create Organization.find(self.organization_id).update_credits end And here's my other model. As you can see what I wrote here is an incorrect way to pass the var def update_credits @organization = Organization.find(params[:id]) credit_count = @organization.card_signup...

RSpec Test Case Doubt

Hi, Following is a test case in RailsTutorial. Generally I understand the syntax, But in this case, they define the @invalid_attr variable, but they dont seem to be using it. Infact in this line @user.should_receive(:update_attributes).and_return(false), I think @user would have all the values from the factory, rather than @inva...

Are there any acts_as_grid plugins?

I'd like to do something like acts_as_list, but in two dimensions, to define a position in a grid. Does this exists anywhere already? Any tips for how to get started? ...

Generating polymorphic routes from objects passed to Liquid Template engine

I'm using Liquid markup in a Rails project that I'm working on, and I'm trying to create a link_to filter. I'd like to be able to generate templates such as the following: <ul> {% for page in edition.pages %} <li>{{page | link_to_page}}</li> {% endfor %} </ul> Where I could use polymorphic routes to generate the link based on t...

rails -- parse military time into AM/PM, using chronic?

Hello, I've been using Chronic, the natural language parser and its awesome. The problem I'm running into now is I cant parse the military time its give me back in to some form of AM/PM time that would be normal for a user to see. <%= Chronic.parse("next monday") %> yields => Mon Jul 05 12:00:00 -0500 2010 Is there a way to go b...

Rails -- Would like to create a controller with a dash or underscore in name

Hello, I wanted to create some basic html pages to add to my rails app. I figured the restful way to do it would be to create a controller. The problem is I'd like the pages to be a two word title. => ex. www.mydomain.com/foo-bar/ For SEO reasons it really must be two words, and I need the separation...using www.mydomain.com/foobar...

drb problem? ringy-dingy won't answer...

The following code works fine as long as I don't try to run it through the distributed server. It doesn't get there... It runs fine out of delayed_job, runs fine if called directly. But if 'distrib' is true (the default) it runs right up to the call to the server and right past it without getting to the server or raising any errors. Am...

validates_uniqueness_of...and unless...

What's the proper way to write? validates_uniqueness_of :a, :scope => [:b, :c], :unless => !d.nil? ...

Advanced Rails Recipes - (4) Toggle Attributes with Ajax

I have implemented David Heinemeier Hansson's article in "Advanced Rails Recipes" called Toggling Attributes with AJAX. I have a question about implementing this fantastic recipe in a more general setting. Hansson's tutorial works when toggling only one type of attribute in one view because the spinner image is named: 'spinner-#{object....

Ruby on Rails Thinking Sphinx facets

I have an application in which I need to implement the faceted search functionality on one of the fields of the associated models and it does not seem to be working. Here is a brief context: There are 3 models I am working on: 1. Product 2. Attributes 3. ProductAttributes. Please see the code spnippets below: class Product < ActiveReco...

Ruby attr_accessor setter does not get called during update_attributes on child object

I'm trying to add functionality to a project done in ruby, I'm unfamiliar with Ruby, but have managed to create a project review page that allows updates on the project task codes for a given monthly review. My issue is that the client (my brother) has asked me to allow him to edit the scheduled hours for the next few months on "this"...

How to access an instance variable inside a Javascript function in Ruby on Rails application?

I have a form for editing profiles. Rails automatically generates the form id as 'edit_profile_##' where ## is the profile id of the current user(instance variable-@profile_id). I need to use this form id for my javascript functions. Is there a way to get the current user's profile id inside js? Or is there a way I can override the autom...

Predetermining redirect_to for awesome navigation

I have a slightly complex navigational system with numerous landing pages, multipage forms, and multiple ways of accessing the standard CRUD functions. Objective: To maintain a variable such as (params[:target]) throughout the system such that each controller knows where to redirect a user based on the location and circumstances of the ...

How can I cache a page manually in RoR?

I am trying to create a site in RoR and have enabled caching for some pages and actions. The related DB may not accessible every time and hence using the cache is very much required. Hence I cant wait for someone to actually visit the page, render it and then cache it. Instead I want whatever is cache-able to be cached manually, programa...