ruby-on-rails

An affordable way to use multiple Delayed::Job queues

I have a Ruby on Rails app that needs process many background jobs simultaneously: anywhere from 5-6 at a time to up to 50-60 at a time depending on the time of day. Right now my app is running on Heroku, which charges $.05/hour per worker, regardless of how much CPU or memory the worker is using. This is costing me a boatload each month...

how to overwrite rcov method with loading custom file

I use rcov 0.9.8 on ruby 1.9.1 and rvm for ROR application. Rcov has problem on ruby 1.9. I found solution for encoding problems from here. --- lib/rcov/code_coverage_analyzer.rb~ 2010-03-21 16:15:47.000000000 +0100 +++ lib/rcov/code_coverage_analyzer.rb 2010-03-21 16:11:49.000000000 +0100 @@ -250,6 +250,10 @@ end def update...

Adding custom :new routes using Rails 3 routing

In Rails 2 we can add custom new actions to resourceful routes, like: map.resources :users, :new => {:apply => :get} How do we achieve the same thing in Rails 3? resources :users do get :apply, :on => :new # does not work new do get :apply # also does not work end end Any ideas? ...

dynamic link_to_remote in rails with jquery

Hi I'm trying to pass a string with a link_to_remote call as the :id, and the string should be collected from an input field with and id of "movie_title". <div id="search_list">Nothing here yet</div> <br /> <% semantic_form_for @movie do |f| %> <% f.inputs do -%> <%= f.input :title, :class => "movie_title" %> <%= link_to_r...

rails script/generate scaffold problem

I'm new to rails and was trying out the scaffold command - the following scaffold runs and works when I view it via web brick script/generate scaffold book title:string the following fails - gives me a weird route error script/generate scaffold application name:string the following works script/generate scaffold app name:string can...

Retrieving created_at value in Rails?

Is there a way I could retrieve created_at value from the Database in Rails? The table has columns like ticket_created, ticket_updated. By default a created_at column is also included. If I try doing: @tickets = Ticket.find(:all) for ticket in @tickets puts ticket.created_at end the above code is returning ticket_created i...

undefined method `openid_identifier' for #<AccountSession: no credentials provided>

I am trying to get authlogic and openid happening in my app. So far its been seriously unpleasant. I have tried to follow the Railscasts on the topic but none of the gems or plugins seem to work. A after reading about a previous error I ended up installing this open-id plugin (mentioned at the bottom of that page). Now I am getting the ...

Dynamic class_name for has_many relations

I'm trying to make has_many relation with dynamic class_name attribute class Category < ActiveRecord::Base has_many :ads, :class_name => ( lambda { return self.item_type } ) end or class Category < ActiveRecord::Base has_many :ads, :class_name => self.item_type end But i got errors: can't convert Proc into String or undefi...

Ruby/JRuby and WEBrick serving requests one at a time

Does anyone knows how to force WEBrick to process more than one request at a time? I'm using some Ajax on my page for long running database-related tasks and I can clearly see the requests are being processed in a pipeline. ...

Rails 2.3 using another model's named_scope or alternative

Hi Let's say I have two models like so: class Comment < ActiveRecord::Base belongs_to :user named_scope :about_x :conditions => "comments.text like '%x%')" end class User < ActiveRecord::Base has_many :comments end I would like to use the models so that I can return all the users and all comments with text like '%x%' all_use...

How to version SQL Server schema using VS 2005?

I am new to C# programming and am coming to it most recently from working with Ruby on Rails. In RoR, I am used to being able to write schema migrations for the database. I would like to be able to do something similar for my C#/SQLServer projects. Does such a tool exist for the VS 2005 toolset? Would it be wise to use RoR migrations...

How to create a MySQL query for time based elements with a 'safe window'?

I am no SQL expert, far from it. I am writing a Rails application, and I am new at that as well. I come from a desktop programming background. My application has a table of data, one of the columns is the time at which the data was logged. I want to create a query with a 'safe window' around EACH row. By that I mean, it returns the ...

What are the Rails best practices for javascript templates in restful/resourceful controllers?

First, 2 common (basic) approaches: # returning from some FoosController method respond_to do |format| # 1. render the javascript directly format.js { render :json => @foo.to_json } # 2. render the default template, say update.js.erb format.js { render } end # in update.js.erb $('#foo').html("<%= escape_javascript(render(@foo)...

Rails 2.3: using another models named_scope inside another named_scope

Hi Let's say I have two models like so: class Comment < ActiveRecord::Base belongs_to :user named_scope :about_x :conditions => "comments.text like '%x%')" end class User < ActiveRecord::Base has_many :comments end How can I add a named_scope to the user model like so class User < ActiveRecord::Base has_many :comments nam...

belongs_to with a custom class_name not producing proper foreign key in Rails 3

I am updating an application to Rails 3 and I am having trouble creating a custom foreign key. I have something like this: class Product < ActiveRecord::Base belongs_to :owner, :class_name => 'User' ... end class User < ActiveRecord::Base has_many :products ... end class ProductsController < ApplicationController before_filter ...

Share authentication between application using Devise and Ruby on Rails

As the topic says. How do I share the authentication between different applications on the same server? ...

Simple search form passing the searched string through GET

Hi, I'd like my Search form to return the following url after submit: /anuncios/buscar/the_text_I_searched My form is the following: <% form_for :announcement, :url => search_path(:txtSearch) do |f| %> <div class="searchBox" id="basic"> <%= text_field_tag :txtSearch, params[:str_search].blank? ? "Busc&aacute; tu curso r&aacute...

rails: Get all items tagged x AND y AND z

I've got two models: Item and Tag. Both have a name attribute. I want to find items tagged with several tags. class Item < ActiveRecord::Base has_many :tags validates_presence_of :name end class Tag < ActiveRecord::Base belongs_to :item validates_presence_of :name end Given a list of tag ids, I can easily enough get the list ...

Haml::SyntaxError in Static#home?

I have this Haml: #index-header %h1 Supersonic Mac Software. %p Some motto %h1 Our Software %p Which will once becoume your's .third-column %h2 Product 1 %p LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL LOL .third-column %h2...

Doing a DELETE request from <a> tag without constructing forms?

Is there any way to force an <a href> to do a delete request when clicked instead of a regular GET? The "Rails" way is to dynamically generate a <form> tag that adds the appropriate params so that it gets routed to the right place, however I'm not too fond of that much DOM manipulation for such a simple task. I thought about going the ...