ruby-on-rails

'memcache-client' problem - app can't load the gem

Hi all - i'm trying to get memcached and the Interlock plugin working with a new rails app. The weird thing is that they both work fine in another app on the same machine and i can't figure out the difference that's stopping this app. The new app is rails 2.3.4 and the old one is 2.2.2 in case that's a factor. When the app starts, i...

ruby1.9.1 - sqlite3 problem on ubuntu 9.10 x64 (no such file to load -- sqlite3)

Hi, I have problem with sqlite3, because it is not working. irb(main):001:0> require 'sqlite3' LoadError: no such file to load -- sqlite3 from (irb):1:in `require' from (irb):1 from /usr/bin/irb:12:in `<main>' I have installed following packages: sudo apt-get install ruby1.9.1-full sudo apt-get install rubygems1.9.1 sudo...

RSpec and Cucumber with Rails

After running command "ruby script/cucumber" it produces the error as Using the default profile... e:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/gem_dependency.rb:119:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010. Use #requirement e:/Ruby/lib/ruby/gems/1.8/gems/activesup...

Debugger in class method ends up in the controller

I have a controller with a action similar to this class EventsController < ApplicationController .... def test Events.first.test end .... end and a model similar to this class Event < ActiveRecord::Base .... def test debugger end .... end What confuses me is that, when the action is tri...

Polymorphic Paperclip overwriting files with the same names

Hi, in Rails using the Polymorphic version of Paperclip, the default saving technique means that files with the same name overwrite each other. Including the :id in the path and URL doesn't work as it just overwrites the earlier file with the old :id. I've tried interpolations using a time-stamp, but it just looks for the current time w...

Idempotency for increment via PUT

How to achieve itempotency when incrementing a database column via PUT? (For example a credits-count in a purchase process) ...

Testing routes with host constraints via assert_routing in Rails

I have a route which I'm using constraints to check the host and then a route which is essentially the same but without the host restriction (these are really namespaces but to make things simple this example will do): match "/(:page_key)" => "namespace_one/pages#show", :constraints => proc {|env| env['SERVER_NAME'] == 'test.mysite.loc...

find untranslated locales in rails.

Hi, I'm using rails 2.3.5 with i18n. I's there a way to find all not yet translated locales in all views? Maybe a after_filter in the application controller, but which code I can use for this job? thanks ...

fields_for form builder object is nil

Any way to access a nested form_bulder.object? ## controller @project = Project.new @project.tasks.build form_for(@project) do |f| f.object.nil? ## returns false fields_for :tasks do |builder| builder.object.nil? ## returns true end end ...

Save Rails ActiveRecord objects into a temporary table (MySQL)

A user can import data into our website from a file. The data normally contains several hundred Items (Item < ActiveRecord::Base). Although the validations help, they cannot solve the problem of sanity-checking the content. For that we would like to have a test mode. Could we use a temporary Items table for this with Rails/MySQL, and,...

undefined method error appears in erb but not haml

Hey all, All I wanted to do was convert a haml file to erb. After doing so, i get an undefined method `render_sequence_nav' error message. Even though no such error happened when it was in haml format. In the haml file, there is this line: #fields << render_sequence_nav(sequence_info, students_path) fields << render(:partial => ...

Pubsubhubbub on Rails. How to extract the raw POST body contents from the POST request?

I am having trouble setting up a pubsub enabled subscriber app using rails. I have currently subscribed to the open hub pubsubhubbub.appspot.com and am receiving pings to my application's endpoint. (as of now i have created a counter which increments everytime the end point is pinged). But i am not able to understand as to how to extract...

Best way to create random DateTime in Rails

What do you think the best way to generate a random DateTime in rails is? I am currently using the random_data gem to produce a random date, but it defaults all times at 12:00 AM. Here is an idea of what I'm trying to do (it's for a seeds.rb file). Also, maybe a random price within a certain range? I'm thinking I would need some sort of...

Adding title to rails route

I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the id of the list. What I would like to do is add the title of the list the url so it it more informative(for google or whatever). So I would like it to look like: www.mysite.com/lists/123/title-of-list-number-123 How do you go about adding to a u...

Rails belongs_to association, can't access owner's attributes when part of a collection?

I have an Object, Ball, which belongs_to a Girl, which can have_many balls. Everything works for the most part, but if I try to print out the girls' name via: @balls.each do |b| b.girl.name end I get the following error: "undefined method `name' for nil:NilClass" Which really confuses me. If I say b.girl.class, I get it as an i...

Rails: How can I loop through validation errors?

I'm building an API for my app and would like to return errors in the XML response that are generated by validation errors. So say you're registering on the site, right now the validation errors returned might be: Login has already been taken Password is too short (minimum is 6 characters) Email has already been taken But I'd like to...

Confused as to which Prototype helper to use (updated)

This is a continuation of http://stackoverflow.com/questions/2397874/confused-as-to-which-prototype-helper-to-use. My code has been updated to reflect other user's suggestions: (model) message.rb: class Message < ActiveRecord::Base after_create :destroy_old_messages def old_messages messages = Message.all(:order => 'updated_at ...

Is there a shorter name for Rails find_or_initialize_by_this_that_and_theotherthing?

I use the active record find_or_intialize (similar to find_or_create) in a few places, which leads to annoyingly long non-breakable method names. For example, "find_or_initialize_by_topic_id_and_publish_date_and_publist_id" really messes up my formatting. I know with the normal find method I can supply all this stuff as parameters. Is th...

How to pre-process CSV data for FasterCSV?

We're having a significant number of problems creating a bulk upload function for our little app. We're using the FasterCSV gem to upload data to a MySQL database but he Faster CSV is so twitchy and precise in its requirements that it constantly breaks with malformed CSV errors and time out errors. The csv files are generally created b...

how to make a variable seen in all views - rails

so i have many controllers and many views. i want my variable @random_quote to be evaluated each time every view loads up. i tried several things in application controller(i thought it should be here?) but none of them worked. so how do i connect these two: @random_quote.body (in view) and @random_quote = Quote.find(:random) (in c...