ruby

Rails - Paperclip validating attachment size when it shouldn't be?

I've got a rails model using Paperclip that looks like this: has_attached_file :image, :styles => { :normal => ['857x392#', :png] }, :url => '/assets/pages/:id/:basename.:extension', :path => ':rails_root/public/assets/pages/:id/:basename.:extension' validates_attachment_size :image, :less_th...

What is wrong with my logic in a rails hash?

I have a setting in environment/production.rb of HEROKU = true This should change my has_attachment has to use s3 instead of the file system, but it doesn't. What's wrong with my logic? has_attachment :content_type => :image, :storage => ($HEROKU ? :s3 : :file_system), ... Thanks! ...

Executing user-supplied ruby code on a web server

I would like to let my users create Ruby scripts that do computation on some data residing on the web server and then outputs results. The scripts are executed on the server. Is there any way to do this securely? More specifically, I would like to: restrict the resources the script can use (memory and cpu), and limit its running time ...

acts_as_tree to nested JSON hashes

My goal is to print a json document with the structure described in the chosen answer on this thread. I only have one level of sub categories (2 total, including root) so it should be a little bit easier than the problem there. The problem I'm having is with efficiency. With only ~20 root categories the recursion is causing my script to ...

Accessing SSL enabled Google Apps feed with http protocol

Building an app using a calendar on a Google Apps domain that has SSL enforced domain-wide. I initially found the problem when building a Rails app using the GCal4Ruby library, which used the allcalendars feed URL with a non-SSL protocol (GCal4Ruby debug output snippet [sic]): … url = http://www.google.com/calendar/feeds/default/allcale...

How can I change the link format in will_paginate for page_cache in Ruby on Rails?

I want to use page_cache with will_paginate. There are good information on this page below. http://railsenvy.com/2007/2/28/rails-caching-tutorial#pagination http://railslab.newrelic.com/2009/02/05/episode-5-advanced-page-caching I wrote routes.rb looks like: map.connect '/products/page/:page', :controller => 'products', :action => 'i...

Representing ecommerce products and variations cleanly in the database

I have an ecommerce store that I am building. I am using Rails/ActiveRecord, but that really isn't necessary to answer this question (however, if you are familiar with those things, please feel free to answer in terms of Rails/AR). One of the store's requirements is that it needs to represent two types of products: Simple products - t...

Merb multidomain session cookie

Hello there Is there a way to set session cookie work for all subdomains (e.g. *.domain.com) from Merb configuration file (config/init.rb) Looking for something like Merb::Config.use do |c| c[:session_cookie_domain] = '.domain.com' end ...

Rails - Shared Database Tables between two apps

We’ll be releasing shortly a companion Rails application to our existing Rails app. We will be running the companion app alongside our existing app on the same servers. My question concerns the databases. My hosting provider generally would configure a 2nd distinct database for the new application - secondappname_production. However,...

sorting a multidimensional array in ruby

I have the following array: [["2010-01-10", 2], ["2010-01-09", 5], ["2009-12-11", 3], ["2009-12-12", 12], ["2009-12-13", 0]] I just want to sort it by the second value in each group and return the highest one, like i want to the output to be 12 with the given input above. update I might add that I made this into an array using to_a, ...

Live Search / auto_complete + HABTM = possible?

I am attempting to add in a form field that should allow me to add a record into a join table. The table name contains the ids of the following: log_id node_id So naturally, my models is setup as follows: class Log has_and_belongs_to_many :nodes end class Node has_and_belongs_to_many :nodes end The objective is that when I crea...

Profile a C shared library called by Ruby program

I have a program written in Ruby and C. The C portion is a shared library, which is an extension for the Ruby program. I want to profile the C shared library I wrote, using gprof. I compile the shared library like this: gcc -I. -I/usr/lib/ruby/1.8/i486-linux -I/usr/lib/ruby/1.8/i486-linux -I. -D_FILE_OFFSET_BITS=64 -fPIC -fno-strict-al...

How to specify method default argument using define_method?

define_mehtod could be used to define methods: define_method(:m) do |a| end which is equivalent to the following: def m(a) end However, what is the equivalent form of the following using define_method: def m(a=false) end Note that I'd need to be able to call m() without giving any argument. ...

date_select Ruby

How do I extend the range of the date_select in Ruby? It only goes as far as 2005 and I'd like to use it for the date of birth. ...

authlogic - cause for unsuccessful session creation and no error messages (with formtastic)

Hi, I have 2 questions about authlogic: 1 - how to get cause of unsuccessful session creation (for example - not confirmed, blocked, wrong pass etc) to use it in app logic (route to another page for confimation, or re-enter pass etc)? 2 - question about integration formtastic and authlogic. How to show error messages on session creatio...

Can I find out if an object is being referenced?

If I have two objects, one being referenced in another. Then in the first object can I write a method which will give me which other objects it is being referenced in? ...

Ruby testing: block vs. method

As I've been writing test suites for a Rails app, I've noticed that there are two different ways to create tests, a test block and a regular method: test "the truth" do assert true end vs. def test_for_something_else assert true end Is there any difference between the two testing structures? When should I use one over the othe...

Passing options in autospec with Cucumber in Ruby on Rails Development

I always run autospec to run features and RSpec at the same time, but running all the features is often time-consuming on my local computer. I would run every feature before committing code. I would like to pass the argument in autospec command. autospec doesn't obviously doesn't accept the arguments directly. Here's the output of autos...

How do I change the aws-ruby log location?

I've found the method set_log in the documentation, I just can't figure out the syntax to call it. Here's what I tried: require 'ruby-aws' Amazon::Util::Logging.set_log('my.log') NoMethodError: undefined method `set_log' for Amazon::Util::Logging:Module ...

How to let the page reload specify div in RoR?

I modify my RoR application to calling a create.js.rjs after created an item. I want to reload a specify div in my page after I create an item, how can I do that? When my div have a ruby object like this: <div id="categoryList"> <% @categories.each do |category| %> <%= content_tag(:dt, category.name, :class => "menu-table")%><%...