ruby-on-rails

ActiveRecord::EagerLoadPolymorphicError: Can not eagerly load the polymorphic association

class Transaction < ActiveRecord::Base belongs_to :account, :polymorphic => true end class Bankaccount < ActiveRecord::Base has_many :transactions, :as => :account end class Creditcard < ActiveRecord::Base has_many :transactions, :as => :account end Trying to do a summation of transactions where the account is active. Transacti...

Is there any way to non-verbosely output all dependencies using to_json?

In Rails apps, I find myself placing a lot of nested :include => statements in my JSON rendering code to include objects with relationships(direct and indirect) to the root object. Is there any way to get to_json(or a similar method) to automatically include all related objects without explicitly specifying them? ...

button_to_remote :html => {}

Greetings, I am trying to get a button to generate with id="view-blog-1-comments" and it seems the button_to_remote function is ignoring my call. Could some one set me straight on what I am doing wrong here. <%= button_to_remote 'View Comments', :url => blog_comments_path(blog), :html => {:id => "view-blog-#{b...

Rails partials: help with require

I'm fairly new to Rails and am trying to figure out how to add a method to the String class and have the code in my partial know that the String class has been added to. I'm not sure where I should put the require statement. ...

Rails partials: Trouble finding where to put reference to new method in my partial

I'm fairly new to Rails and am trying to figure out how to add a method to the ActiveView class so I can then access a new method from the partials. Here's some sample code: %li =link_to "#{h aim_small.description.shorten} #{"(current aim)" if aim_small.description == current_aim.description}", :action => 'show', :id => aim_small ....

Rails model passes validation but view still renders errors?

Oddly enough, my model passes validation just fine, and acts as expected, however I still have the error rendered to the view. # Controller def up @vote = Vote.create :vote => true, :voter => current_user, :voteable => Recipe.find(params[:id]) respond_to do |format| format.js { render :json => {:model => 'vote', :success => @vot...

Recurring tasks in a Ruby On Rails application: Cron or other?

I am currently writing an application that pulls new information from RSS sources and has to update those RSS sources in a certain frequency. Currently I am pulling only when the user requests a feed but I want to change that behavior to automatic periodic fetching. I was writing a shellscript that would interact with the database and g...

ruby/rails NoMethodError? when using custom validation method

hi all, i'v been new to ruby and rails and encountered a rather strange error: class Person < ActiveRecord::Base validates_presence_of :description, :if => require_description_presence? def require_description_presence? self.can_send_email end end raises NoMethodError in PeopleController#index undefined method ...

ActiveRecord serialize using JSON instead of YAML

I have a model that uses a serialized column: class Form < ActiveRecord::Base serialize :options, Hash end Is there a way to make this serialization use JSON instead of YAML? ...

Sphinx on Webfaction for Rails

I'm looking to install Sphinx and thinking_sphinx on my basic shared hosting plan at webfaction so I can properly deploy my rails app. I'm positive webfaction supports this under my plan. I'm not anything near a linux guru in terms of skill level, but I know the basics. How can I install Sphinx on my shared host without having sudo priv...

jquery date picker split into multiple fields

I have the usual Jquery datepicker working fine. But I want to feed it into a set of selectboxes rather than one textfield. I have had success feeding it into one select field with a specific format but am unsure how to feed all three into different fields with different formats. $(document).ready(function(){ $("#search_startdate")....

how to insert rows into heroku table

I just pushed my local rails app to heroku and then ran heroku rake db:migrate This created all the tables and stuff on my heroku server. However, I have just 4 rows in a table which I would like to insert into tables just created on heroku. So I used heroku db:push But this gives me an error Auto-detected local database...

Ruby on Rails - Accessing data in :has_many => :through association

Hi, I'm trying to get to grips with this type of association in Rails I have the following three models: User has_many: 'memberships' has_many: groups, :through => 'memberships' Membership belongs_to: 'user' belongs_to 'group' Group has_many: 'memberships' has_many: 'users', :through => 'memberships' I have a before_create metho...

Formatting ERB Templates automatically in textmate

When writing ERB templates in Ruby on Rails using Textmate formatting by hand pretty much sucks. Do anyone know of a textmate bundle that handles formatting of ERB templates/views? My googling has found nothing. Thanks! ...

bad ETag value in test and production environment

i'm using the new caching solution for Rails as described here. the development environment works fine, but the test and production sends invalid ETag header ignores the parameter of the stale? function. heres is the corresponding part of one of my controllers: def index @categories = Category.all if stale?(:etag => @categories) ...

Check on TEST mode during runtime

My web application writes some kind of log during runtime. I don't want to write this log when running my test suite using cucumber. So, how can I check my current runtime environment (TEST, DEV or PROD)? I'm looking for the C equivalent to i.e. : #ifdef DEBUG    // just run in debug mode #endif Thank you very much for ...

prawnto displaying tables that don't break when new page

Hi all I have a variable number of tables with variable number of rows and I want to have them displaying one after the other but if a table doesn't fit on the current page put it on the next then continue on. I have put the table in a transaction so I can roll back then print it if the height will fit on curent page but how do I get th...

How to implement a "global ID system" in a diverse environment?

I am looking into creating a global ID system for all of our online products including our own company web site (we don't have any products that are public quite yet, but we are fairly close). If we were completely a .Net shop this wouldn't be much of an issue, but we have at least ASP.Net MVC and Ruby on Rails, and who knows what else w...

Get Activerecord list of associated objects from list of objects

Hello, I'm fairly new to Rails, and so I apologise if this is a daft question. I've tried looking around the web for the answer, but I'm not totally sure on the terminology and so I'm finding it really difficult to get an answer. Basically, I have two models 'Group' and 'Category'. Groups has_one Categories, and Categories belongs_to ...

Rails ajax request load view html only

Hi guys, I'm trying to make an AJAX enabled web page using rails and jQuery. The problem that I am running into is that when I try and load a view into a div using jQuery's AJAX method I am getting my application layout returned with the view. Is there a way to only retrieve the view data if it's an AJAX request, but load my application...