ruby-on-rails

Convert times created by Javascript's getTime() method to ruby Time objects

Javascript's getTime() method returns the number of milliseconds since midnight of January 1, 1970. How do I convert the output of getTime() to a Ruby Time object? ...

ActiveRecord error messages: translation for fields

I've used the instructions specifies in http://guides.rubyonrails.org/i18n.html to translate fields of my model, but the labels doesn't come translated. What I'm doing wrong. I have a User model with the field name and I'd like to have it translated to Brazilian Portugues (pt_br), so I got my pt_br.yml: pt_br: errors: "Erro!" a...

Convert Time from one time zone to another in Rails

My created_at timestamps are stored in UTC: >> Annotation.last.created_at => Sat, 29 Aug 2009 23:30:09 UTC +00:00 How do I convert one of them to 'Eastern Time (US & Canada)' (taking into account daylight savings)? Something like: Annotation.last.created_at.in_eastern_time ...

Timeout Error with Hpricot in Rails Controller

Hey--I'm writing a basic Rails app that uses the digg API. I'm trying to parse the xml data that digg's api provides with hpricot, but when testing the page, the browser hangs until I eventually catch the Timeout::Error exception. Here's the code for the controller: require 'rubygems' require 'hpricot' require 'open-uri' appkey = 'htt...

how to properly extend ActionController in rails plugin

I'm writing a Rails plugin (lets call it Foo). I want it to provide 'bar' class function in controllers, so that I can do: class ApplicationController bar ... end bar is defined from withing the plugin loading file vendor/plugins/foo/init.rb. Something like class ActionController::Base def self.bar ... end end The problem...

When should new .NET projects be designed for .NET 4 Framework

I am preparing to start on a new short-term contract (1-2 months) that involves replacing an Access application by moving it to ASP.NET and SQL Server. I am only responsible for the ASP part and connecting it to the database. The only requirement is that whatever technologies I use be relatively well-known in the area, so that if they ...

Uploading a file to a directory outside of RAILS ROOT with attachment_fu

Hi all, I'm trying to use attachment_fu to upload files to a directory outside of the RAILS_ROOT. I want the files to be saved to ~/APP_NAME/uploads/ so that they can be approved/rejected before becoming publicly available. I've tried the following configuration for has_attachment: has_attachment :storage => :file_system, ...

How do I define synthetic attributes for an ActiveRecord model?

I have an ActiveRecord model whose fields mostly come from the database. There are additional attributes, which come from a nested serialised blob of stuff. This has been done so that I can use these attributes from forms without having to jump through hoops (or so I thought in the beginning, anyway) while allowing forwards and backwar...

Need WebCalendar like Functionality with Rails or Ruby

I need an end-to-end Calendar, Schedule Management Solution that integrates with my Rails Application. I need it to be able to handle events, meetings, reminders, exports and imports etc. Something Like WebCalendar is for Php. I know there is a Google Calendar API available for Ruby but I am not sure if that's suitable for internal ...

How to mock/stub a model in Cucumber tests

The scenario is as follows. My Order model has an after_create that contacts a remote payment gateway to retrieve a payment URL. In my Cucumber tests I don't want to perform this action, but return an arbitrary URL. My current cucumber tests looks like this: Given there is a product "Product X" When I enter my credentials And I cl...

Inflections seem to not get loaded in test environment of a rails app

I have a model named Aggelia (it's greek for classified ad) and have set an inflection in RAILS_ROOT/config/initializers/inflections.rb like so: ActiveSupport::Inflector.inflections do |inflect| inflect.irregular 'aggelia', 'aggelies' end It works fine in the development environment but when I try to run the tests (only assert truth...

Accessing date() variables send from the date helper in rails

Hay, not sure if i've missed the point of the helpers in rails, but i used the date() helper and now i don't know how to access the variables returned. Heres the helper code <%=date_select("game", "release_date", :order => [:day, :month, :year])%> How do i access the returned variables in a controller? Thanks ...

Serving files over HTTPS dynamically based on request.ssl? with Attachment_fu

I see there is a :user_ssl option in attachment_fu which checks the amazon_s3.yml file in order to serve files via https:// In the s3_backend.rb you have this method: def self.protocol @protocol ||= s3_config[:use_ssl] ? 'https://' : 'http://' end But this then makes it serve ALL s3 attachments with SSL. I'd like to mak...

Rails' form_tag helper doesn't submit using HTTPS?

I want to protect the login form of my Rails application using HTTPS. After a bit of a uphill struggle I now have the SSL certificate installed and Apache/Passenger set up correctly. My application uses SSL Requirement and RESTful Authentication in combination for the login form. I've noticed using Firebug that the login credentials are...

good way to handle a bunch of data in a hash.

I'm returning a complex result of indeterminate size that I will need to handle again and again, so I'm wondering what is a good way to package it? something like this loop>>> @results = { external_id => { :name => name, :type => type } } or @results = [ { :external_id => external_id, :name => name, :type => type } ] or? end>>>...

Are rails controllers multithreaded? Thread.exclusive in controllers

Are Rails controllers multithreaded? If so, can I protect a certain piece of code (which fires only once every ten minutes) from being run from multiple threads by simply doing require 'thread' Thread.exclusive do # stuff here end on do I need to somehow synchronize on a monitor? ...

Complicated named_scope: Find users who don't belong to a certain project

I'm trying to create a named scope like User.not_in_project(project) but I can't find the right way. I have Users, Projects and Duties as a join model: class User < ActiveRecord::Base has_many :duties, :extend => FindByAssociatedExtension has_many :projects, :through => :duties end class Duty < ActiveRecord::Base belongs_to :use...

What is the difference between Ruby Gem and Rails plugin?

As far as I know, the only difference is in "installation". I've also heard that plugins are somehow harder to update. But would I want to install something as a plugin instead of gem? ...

ZenTest autotest can't find rubygems

I have a rails project that runs fine in development and production and the tests pass when I do a rake test but when I try to autotest it it fails with: Missing the Rails 2.3.3 gem. Please `gem install -v=2.3.3 rails`, blah blah Of course the rails gem is not missing and if I comment this line out, it complains about the rest of the ...

help a n00b understand rails, specifically inheritance, acts_as_nested_set, awesome_nested_set, sortable_element_for_nested_set

hey there, i'm trying to implement a drag and drop interface for a nested set in my first rails project. i'm new to rails so bear with me. my code is basically identical to this project: http://gist.github.com/128779. my problem is in the partial at this line: <% for child in root.direct_children do %> I'm getting a NoMethodError ...