ruby-on-rails

Multi level associations in rails

I am creating an application to track football teams through out the season. but i am stuck on the design of the database. One fixture has a home team and an away team. I have created a fixture model which has two foreign keys- home_team and away_team but I cant get the association to work right. any ideas? Each fixture belongs to a leag...

How to read unicode characters accurately

I have a text file containing what I am told are unicode characters, for example: \320\222\320\21015-25'ish per main or \320\222\320\21020-40'ish per starter Which should read: £15-25'ish per main or £20-40'ish per main starter However, when viewing this text in Firefox, the output is mangled with various unwanted characters. So, ar...

Can I "Unload" a Rails Metal Class after one time use?

I've got a Rails metal class that basically does a one time check to make sure there is an admin user in the system, if not, it redirects user to create one. Right now I'm using the rack session to prevent double checking but that seems to have the following problems: Still does one time check for each session Slows things down by che...

SQL aggregate functions using MIN and AVG...

How can I omit Zeros in my data? For example using the MIN function? I would like the Minimum value except a 0... How can I get the next largest? MIN(availables.price) Also is there a generally way to skip over 0s in the same way if I'm using the AVG function? The problem is the table I've inherited doesn't use NULL values but has...

Ruby thread-safe class variables

I have a number of models that load a collection of strings, based on the user's i18n locale. In order to simplify things, each model that does so includes the following module: module HasStrings def self.included(klass) klass.extend ClassMethods end module ClassMethods def strings @strings ||= reload_strings! e...

Textmate with HTML(rails) Problem

Hi, I am editing a .html.erb file with HTML(rails) selected at the bottom. When I type if I get: < ?php if (condition): ? > < ?php endif ? > Any ideas? Cheers ...

How can I be sure each process in my mongrel_cluster is handling requests?

I have a rails application that takes a while to process certain requests (as it processes image uploads). I currently have three mongrel processes in a cluster, and I expect one of the other two to handle a second request if the first one is busy. However, this doesn't seem to be happening. If I watch the output from top on the ser...

Why is attachment_fu updating every attachment instead of just the changed ones ?

I have a Property model with a has_many and accepts_nested_attributes_for on a Image model which uses attachment_fu. Updating a Property using the following code results in a database UPDATE for every single image (and each image thumbnail) no matter whether there were changes to it or not. properties_controller.rb def update @pr...

Is anybody having issues with comments in html after upgrading to snow leopard?

I just upgraded to Snow Leopard and now I'm having this weird issue. Has anybody seen this issue? Ruby comments in the html are causing weird issues. for exmaple: <!-- /app/views/convs/_conv_detail_wiki.rhtml --> <% # Prereq: conv, # seed %> <% # NOTE: you can implicit pass @keywords to this partial for highlighting purposes %...

rake db:create - collation issues

kratos-iii:railsproj zachinglis$ rake db:create (in /Users/zachinglis/Sites/rails/railsproj) Couldn't create database for {"adapter"=>"mysql", "host"=>"localhost", "username"=>"root", "password"=>nil, "database"=>"railsproj_development"}, charset: utf8, collation: utf8_general_ci (if you set the charset manually, make sure you have a mat...

How to write static file from ActionMailer::receive() w/o duplicating code in Rails?

I'm facing the following challenge for a Rails project: When a user receives mail, I want to invoke a method that writes the message out to a static file. The trick is, the mail needs to be embedded in a styled HTML page (i.e., we will surround the actual message with other page elements and style the whole page). Here's the current a...

Ruby on rails database schema help

Hay guys, I'm a novice to intermediate RoR programmer. However, I'm not too good on setting up relational database's so i need a hand. Basically my app is a book club. A user signs up, the user creates a book club based on a book. Other users joins this club and discusses it (like a forum). I have written a english description of the s...

Ruby on Rails SQL Optimizations

Lets assume: Network has_many Channels Network has_many Nicknames Channel has_many Messages Channel belongs_to Network Nickname has_many Messages Nickname belongs_to Network Additionally: Channel has_many Nicknames, :through => :messages Nicknamehas_many Channel, :through => :messages I have this method here that logs messages. Ver...

How do you debug a Sinatra app like a Rails app?

In my main Sinatra controller, I want to debug the params hash after it is POSTed from a form. I have added: puts params.inspect and set :logging, :true The params.inspect works if everything goes well. But if an error happens before the controller is executed I'm not getting any information about the error like I would in Rails b...

How to save a rendered view as a static file?

My Rails 2.3 app generates a page in HTML/CSS or as a word doc. I'd like to save that html file to the filesystem as a static file (ie. filename.html or filename.doc). I plan to have a preview action w/ the fully rendered page and a 'save report' button. Our users will access those static files later. (I'll save the path to the db.) Any...

How to insert a DOM node a a specific character index in an existing node (with Hpricot or a similar Ruby library)

Suppose I have this HTML: html = <div>Four score and seven years ago</div> What's the best way to insert (say) an anchor tag after the word "score"? Note: I want to do this in terms of DOM manipulation (with Hpricot, e.g.) not in terms of text manipulation (e.g., no regexes) ...

ruby on rails average per day

Referencing this post: http://stackoverflow.com/questions/1272888/ruby-on-rails-average-per-day I'm getting the average per day, which works fine. Until now that the month switched over... I have this code score = (7.days.ago.to_date.to_s(:db)..Date.today.tomorrow.to_s(:db)).map{|dt| [dt, ave_score[dt] || 0]} Which works, but now t...

respond_to 'include' Coming Up Empty Despite Data Existing

I've got a Rails app returning data via JSON and XML. In the controller, I've got something like this: respond_to do |format| format.xml { render :xml => @customers.to_xml(:include => [:invoices])) } end The Rails app returns the customers in a pretty XML doc but it always shows the 'invoices' array as empty (i.e. no data for the r...

Ajax Push Engine

Hi all, are there anyone hear about APE (Ajax Push Engine) before ? I'm building Rails application and trying to create group chat with this APE realtime engine, the problem is how to make Rails communicate with APE Server ? Are there any tutorial or reference on working APE with Rails ? ...

Nifty Generators LayoutHelper Issue

Working on my first Rails project, I used Ryan Bates' Nifty-Generators to create the initial application files. This gives me a LayoutHelper with a title method: def title(page_title, show_title = true) @content_for_title = page_title.to_s @show_title = show_title end In my homepage view, I have a simple title: <%= title "Welcome...