ruby-on-rails

fastercsv parsing to int or other into ActiveRecord

I'm currently importing a CSV into an activerecord element but can't choose to parse the elements as say ints or decimals on a case by case basis using fastercsv. I can either choose to parse everything as an int or the other, or all as strings. I need to parse some columns as ints, some as decimals and some as strings. Otherwise, is th...

How can I synchronize multiple Workling workers?

I have the following situation: Three tasks: A,B,C (Implemented as Workling workers) Two user events (Calls of a controller method) The tasks are triggered this way: The first user event triggers Task A and Task B. Then an optional user event can trigger Task C, but that task must not run until Task A and B are finished. How can ...

How to implement a mailing system with Rails that sends emails in the background

I want to implement a reliable mailing system with Ruby on Rails that sends emails in the background as sending email sometimes takes like 10 seconds or more so I don't want the user to wait. Some ideas I thought of: Write to a table in DB a have a background process that go over and send email (concern: potential many reads/writes to ...

Using a locale-dependent sorting function in Ruby/Rails

What is a good approach to sorting an array of strings in accordance with the current locale? For example the standard Array#sort puts "Ä" after "Z", which is not correct in German. I would have expected the gem I18n to offer a hook for defining my own sorting algorithms or providing collation strings or objects. In my imagination, pas...

Background process in linux using Ruby on Rails

Hi All, I want to do some process such as sending emails or using ffmpeg commands in backgound as it takes to much time. I want it should run in a background. I am using Fedora 10. Also can i check whether my background process is running successfully or not . is it posssible?if yes what would be the steps i should follow.Any help is a...

Parsing to a total DateTime object in Rails

I'm currently given three values in a table A date value in the format of %dd-%mname-%yy (i.e 06-may-05), and am parsing that using Date.parse(input,true) to fix the issue with the leading values. I'm then given a time value in the form of %hh:%mm:%ss.%ms (the ms of which I can take or leave) and a third value of a GMT offset. I can't...

Using :limit and :order in the associated model

Hello, Is there any way i can limit the results of an associated model? This what i was trying to do : <ul> <% account.logins.slice(0,5).sort_by(&:login_date).reverse.each do |login| -%> <li><%=h login.login_date.strftime("%d.%m.%Y")%></li> <% end -%> </ul> I'm trying to get the last five logins of the accou...

Make Sphinx quiet (non-verbose)

I'm using Sphinx through Thinking Sphinx in a Ruby on Rails project. When I create seed data and all the time, it's quite verbose, printing this: using config file '/Users/pupeno/projectx/config/development.sphinx.conf'... indexing index 'user_delta'... collected 7 docs, 0.0 MB collected 0 attr values sorted 0.0 Mvalues, 100.0% done sor...

Extra arguments for Factory Girl

I need to pass extra arguments to factory girl to be used in a callback. Something like this (but more complex really): Factory.define :blog do |blog| blog.name "Blah" blog.after_create do |blog| blog.posts += sample_posts blog.save! end end and then create it with something like this: Factory.create(:blog, :sample_pos...

Fetching email using Ruby on Rails

I need to fetch email from my gmail account using RoR. require 'net/pop' Net::POP3.start('pop.gmail.com', 995, username, password) do |pop| if pop.mails.empty? puts 'No mail.' else #pop.each_mail do |mail| #p mail.header #p mail.pop puts "Mails present" #en...

Beginner's guide for rails

Hello friends i need a book/ tutorials for rails without using scoffold. All the books mentioned in the other questions are creating some depot application or etc using scaffold and then explaining things. I believe in the thing that creating big depot is worthless when you are not getting anything. All of my frnds are suggesting me to g...

Rails authlogic disable_perishable_token_maintenance

I set disable_perishable_token_maintenance(true) in my User model. If I want to create a user, I have to set perishable_token column default value to '' in my users database table. My question is: Is it safe to have empty perishable_token columns? What would you do to make things more secure? ...

STI and accepts_nested_attributes_for in rails

I have models as follows: class Entity < ActiveRecord::Base has_many :addresses accepts_nested_attributes_for :addresses, :reject_if => lambda { |a| a[:label].blank?} , :allow_destroy => true end class Client < Entity before_save :set_type private def set_type self.type = "Client" end end class Address < ActiveRec...

Form to sort an index in rails

I'm a newcomer to Rails. I want to build a simple form that determines the sort order of a list. I've implemented a form in the likes of - <%= radio_button_tag :sort, "rating" %> <%= label_tag :sort_rating, "order by rating" %> <%= radio_button_tag :sort, "name" %> <%= label_tag :sort_name, "order by name" %> And now I am unsure h...

Setting Mime Type for .ogv files in Rails Development Environment

I am playing around with HTML5 video and have the following snippet in an ERB: <video id="movie" width="320" height="240" poster="/test.jpg" preload="none" controls=""> <source src="/test.mp4" type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;"> <source src="/test.ogv" type="video/ogg; codecs=&quot;theora, vorbis&quot;">...

Connection error with heroku db:push with postgresql

I have suddenly started seeing this strange error when trying to push my database to heroku. > heroku db:push Auto-detected local database: postgres://infinity:infinity@localhost/infinity_development?encoding=utf8 Failed to connect to database: Sequel::DatabaseConnectionError -> TypeError wrong argument type String (expected Array) My...

How do I add some inserts in rails migration?

Hi After creating a table (by migration), I want to insert some entries directly. How must I write a migration for this? thanks ...

Include params/request information in Rails logger?

Hi everyone, I'm trying to get some more information into my Rails logs, specifically the requested URI or current params, if available (and I appreciate that they won't always be). However I just don't seem able to. Here's what I've done so far: #config/environments/production.rb config.logger = Logger.new(config.log_path) config.log_...

Suggestion on Database structure for relational data

Hi there. I've been wrestling with this problem for quite a while now and the automatic mails with 'Slow Query' warnings are still popping in. Basically, I have Blogs with a corresponding table as well as a table that keeps track of how many times each Blog has been viewed. This last table has a huge amount of records since this page i...

Handling JSON and HTML templates in jQuery

How do you handle templating HTML and JSON without locking the HTML into javascript strings? I have an ajax-enabled site that presents a lot of dynamic content by interpolating JSON values with HTML. This all works fine. BUT it means I have significant amounts of HTML all through my JavaScript. For example: var template = "<div>Foo:...