ruby-on-rails

Working around memcached's lack of wildcard expiration in Rails fragment caching

I'm working on adding fragment caching to a Rails 3 site that has both logged in and anonymous users, and need to control when parts of the page expire based on when content displayed throughout the site is updated. Midway into this, I discovered that memcached doesn't support regexps for expire_fragment, so now I'm looking for ways arou...

Image Crop Amazon S3 (works offline)

Hey guys, So im trying to get image cropping to work on Amazon S3, I have the following function def update_attributes(att) scaled_img = Magick::ImageList.new(self.photo.to_file) orig_img = Magick::ImageList.new(self.photo.to_file(:original)) scale = orig_img.columns.to_f / scaled_img.columns args = [ att[:x1], att[:y1], att[:...

javascript to display current options_for_select

Hi, I need to display the current selection for select table as a pop up box , where in index.rhtml I have this <SCRIPT LANGUAGE="JavaScript"> function checkData() { var myTest = formid.table_id.options[formid.table_id.selectedIndex].value; alert 'myTest'; } </script> <% form_tag :controller => 'project_controller', :action => 'actio...

PostgreSql + Escape Enter Key from Query Statement ie Enter Key pressed betweent the data.

Suppose we have a textarea in which we put example string. Textbox contain : Earth is revolving around the Sun. But at the time of saving, I just pressed a enter key after "the sun". Now the statements in texbox :: Earth is revolving around the Sun. Now I am trying to fetch the data but unable just because of that enter key press...

Running integration tests with Cucumber/capybara/celerity on a Jruby on Rails application using mysql

I've got an application I've been working on with ruby 1.9.1. I'd like to test the javascript in my UI and the default selenium driver for capybara doesn't support the events I need to test. So I'm going through the process of using rvm to switch the application on to jruby for testing, since apparently celertiy/culerity only work on j...

In Rails, having a Gem extending all its methods to application controller, is it a good practice?

Is it actually common practice to extend all methods of a Gem into the application controller in Rails? Because it seems that Facebooker gem doesn't that, and there is no telling whether the method is from the facebooker gem, or from our internal code. So when we need to upgrade to Facebooker2, it is hard to find all methods that are a...

Save active_record without calling callbacks in rails3

In rails 2 there was a private method on active_records called create_without_callbacks which you could call to save a record into the database without triggering the callbacks associated with that object. This method has disappeared in rails 3, is there any way to achieve the same thing? ...

Alias for column names in Rails.

Hello. I write web-GUI for application and must (!) using names for columns such as 'delete' or 'listen-control' and so on. I find this code but it is dated by 05 Aug 2005 and not works with Rails 3. How can I redefine this names using native Rails mechanism? Is it possible? PS I'm know about problem with hyphens in the Rails. PPS ...

Trying to understand how a Controller uses a Plugin/Module

Ok so I am using some module/lib/plugin (not sure of the exact name), let's say its a authentication/authorization plugin like: http://github.com/technoweenie/restful-authentication class HomeController < ApplicationController some_module_name_here end Now just from adding the code above 'some_module_name_here', I can access t...

Is it possible to share public code through heroku like I can with Github?

On Github, I can send a page link with a file of code. Does Heroku have the same functionality, or do I have to have them clone the project and added as a collaborator to do that? ...

Embedding message replies inside message parent with mongodb using mongoid

I think it's a best practice to embed replies to a specific message inside that message and I'm trying to implement it using mongoid. here is what I have class Message include Mongoid::Document include Mongoid::Timestamps include Mongoid::Paranoia field :subject field :body field :sender_deleted, :type => Boolean, :defaul...

Use Something like Rails Generator for PHP Development

I want to create a command line based tool for PHP Development. It should do something quite similar based on what the rails generator does as well as integrate with rake, as the rake tasks for the DB should also be available. Or is there a ruby framework that allows to build such generators? ...

How to highlight rows in list based on condition

Version 2.3.4 Let's say, I have an items table with some fields, for example: id, name, something, created_at, updated_at, is_dirty. I'm using active scaffold to display a HTML table from it. class ItemsController < ApplicationController layout 'application' active_scaffold :item do |c| c.columns = [ :id, :name, :something ] ...

Does Rails have a method to construct src="foo.php?href=http%3A%2F%2Fexample.com%2F&amp;layout=standard"

It seems that we will need 2 methods, one is CGI.escape and the other might be h (unless we hardcode &amp;. Is there a method that takes an array or hash of params, and compose it into this form? src="foo.php?href=http%3A%2F%2Fexample.com%2F&amp;layout=standard" It is for Rails 2.2.2, so if there is a method in Rails 2.x that can do ...

File upload via hidden iFrame - form nesting problem

Hello, I assume this one is rather a JavaScript/jQuery/DOM question than a Rails question, but it's all due to the way I implemented it in Rails. I am trying to upload files while creating a new object (auction). While the user inputs some data, he shall also have the possibility to upload multiple photos. The main problem is, that th...

Nested Model Forms in Rails For a "Quiz"

Hi, I am trying to build a quiz of sorts. I would like my form to be able to build one question with 4 or more answers. 4 answers are inputted by default with the ability to add more answers dynamically with javascript. I have modeled it off the code in Ryan Bate's railscasts "Nested Model Forms". My dilemma comes with setting the ...

Rails 3: Simple AJAXy Page updates?

I can't believe I've been looking four hours for this simple task, but I have. In Rails 2.3, I could replace one section of a page with this simple code: render :update do |page| page.replace_html "div_id", :partial => "new_content",... end In Rails 3, Ryan Bates has me writing entire new javascript functions, switching from Protot...

An array of nested forms, but I do not want the previous completed objects to show

I have an Object where the object has a nested form of which can be duplicated as needed. To accomplish this I am using : - 2.times { @organization.referrals.build } - form_for @organization do |f| = f.error_messages - f.fields_for :referrals do |qf| = render :partial => 'referral_fields', :locals => {:qf => qf} Now I have tw...

Ruby interface for sqlite3 fails , need help !!! :(

I was trying to install sqlite3 interface for ruby in my Ubuntu 10.10. But i got the following error any suggestions ? ERROR: Error installing sqlite3-ruby: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb extconf.rb:3:in `require': no such file to load -- mkmf (LoadError) from extconf.rb:3 ...

Garb Ruby library for accessing google analytics - how to get segment "non-paid traffic" ??

Hello all, Here is how I build the report, the problem is that we do not know how to pull the segment data for non-paid traffic - please advice. Thanks report = Garb::Report.new(profile, :limit => 10, :sort => :visits.desc, :start_date => (Date.today - 30), :end_date => Date.today, :segment => {:segment_id => "-5"...