ruby-on-rails

How to localize the label of a file_field in Rails?

I want to localize a form in my app so that all the labels are in Finnish. This is easy with all other form components, but how do I do this with a file field? It always seems to give me a label "choose file" in the button and "no file chosen" immediately after the button. ...

Given a date, how can I efficiently calculate the next date in a given sequence (weekly, monthly, annually)?

In my application I have a variety of date sequences, such as Weekly, Monthly and Annually. Given an arbitrary date in the past, I need to calculate the next future date in the sequence. At the moment I'm using a sub-optimal loop. Here's a simplified example (in Ruby/Rails): def calculate_next_date(from_date) next_date = from_date...

Fedex & UPS implementation

Hi, I've been looking for a Ruby implementation of Fedex and UPS. I've been through their documentation, and think it's really overcomplicated (I'm a bit of a ruby "newbie" myself), so was looking for something simpler. I would only like to use the tracking function. I found a library called shipping (http://shipping.rubyforge.org/), b...

rails complex form and ordering with build

I have complex form similar to a recent Ryan Bates screencast The nested elements work fine however. I'm creating or updating a grid of data such as this through a form where the day's prices are the input. My problem begins when they leave one blank. I have the nested_attributes_for option for not saving nils and it works, if they o...

Ruby on Rails Model.find generates a MySQL error

I have Product model and it has many categories with a has_many :through association In my controller I am trying to do a find by with categories.category but it comes up with a mysql error. Model.find(:all, :conditions => ['categories.category_id = ?', @category.id ]) Ideas? ...

How to use in_place_edit plugin for rails with partials?

I am using the "in_place_editing" plugin for rails to render a form with in-place edits. Thing work fine as long as the default template is chosen by rails (no 'render' method is invoked inside the controller), but they break down when I try to render a partial using "render :partial => 'partial_name'" call. Is this a known issue (in_pl...

Rails running on WEBrick with HTTP authentication

How to set up HTTP authentication in a Rails application running on WEBrick? ...

Rails global content_for

Example: I have 2 partial _map.haml and _bigmap.haml. :: _map.haml - content_for :map do %script{:type => "text/javascript", :src => "http://maps.google.com/maps/api/js?sensor=true"} ... :: _bigmap.haml - content_for :bigmap do %script{:type => "text/javascript", :src => "http://maps.google.com/maps/api/js?sensor=true"} .....

Testing HABTM associations with rails/cucumber.

How am I supposed to test the typical User <-habtm-> Groups story. My Users and groups are created with factory_girl, it means I don't know the group id so I cannot ask webrat to check the checkbox. Thank you for any webrat steps hints ...

Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again (I have rubygems 1.3.6!)

I'm running rails version 2.3.5 and rubygems version 1.3.6, when I script/server I get this error Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again:http://rubygems.rubyforge.org any ideas how to fix this? ...

The next big thing from a career point of view?

I love programming. It keeps me busy, interested and I get some satisfaction after crossing a brick wall. I still have a year to go before I graduate. I like Java, but there is a lot of competition for entry level positions in Java. I am familiar with PHP and I am doing a project in PHP. I want to be very good at something which will b...

How do I fix Stack Overflow after upgrading rails 2.0.2 to 2.3.5 (or even 2.1.0) => problem appears in ActiveRecord::SessionStore

Ok, so we're upgrading a client's legacy code from 2.0.2 to latest rails. Most of the basics were easy to fix, but I can't get to the admin screens. Every time we hit "current_user" we get a "stack level too deep" error. I've dug deeply into the code (read: flailed around a lot at random) and I've finally narrowed it down to the ActiveR...

Long running tasks in Rails

I have a controller that generates HTML, XML, and CSV reports. The queries used for these reports take over a minute to return their result. What is the best approach to run these tasks in the background and then return the result to the user? I have looked into Backgroundrb. Is there anything more basic for my needs? ...

Difference Between Rails 2.2 and 2.3.5? ActionMailer.Utils

I would think this is a Ruby difference, but I'm using the same Ruby version 1.8.7. This is related to this post (to answer "why do you need this?"). This code works in 2.2.2 Loading development environment (Rails 2.2.2) >> module ActionMailer >> Utils.normalize_new_lines("blah") >> end but in 2.3.5 it fails Loading development envir...

Security in rails Active resources

How to use cryptography with XML documents used for rails Active resources? Or, is there any way to garantee security and integrity with comunications through rails Active resources? ...

Domain / Subdomain routing and using namespaced controllers

I am currently directing all traffic that is subdomained and/or cnamed to my site to a controller called external and a method called handler. This has gotten really messy and I would like to clean it up. I would like all external requests to be handled the normal rails way ":controller/:action/:id" however, I want these controllers in...

rails will_paginate and sorting with page caching

Hi! I have a website where in the category 'show' action a list of products is shown. I successfully paginate with the will_paginate plugin and made this work with page caching by configuring my routes like Sean Behan does: http://seanbehan.com/ruby-on-rails/how-to-use-pretty-urls-with-rails-will_paginate-plugin/. But I would love to ...

Rails Nested editing form for self-referential HABTM Active Record Object

OK, this one is a doozy. I have an ActiveRecord object that, among other things, includes a relationships as follows: class Sample < ActiveRecord::Base has_and_belongs_to_many :related_samples, :class_name => "Sample", :join_table => "related_samples", :for...

Running SQL on a model that I got from a gem

So, I'm working on a project that uses the acts_as_taggable_on_steroids gem. I've installed it as a gem, and it works great and all. Here's where I'm running into problems though - I want to generate a list of the top 25 used tags, and the number of times they've been used across all taggable items. Well, as it happens, acts_as_taggable...

Evaluating string templates

I have a string template as shown below template = '<p class="foo">#{content}</p>' I want to evaluate the template based on current value of the variable called content. html = my_eval(template, "Hello World") This is my current approach for this problem: def my_eval template, content "\"#{template.gsub('"', '\"')}\"" # gsub to...