ruby-on-rails

CGI Issues on Apache in a 64-bit Operating System

I have a Ruby on Rails application that uses Apache as web server and my application calls a CGI for some time. This was installed in Windows Server 2008 R2 64-bit. My problem is, the CGI is not working as expected, Apache says 'premature end of script'. I am sure that there is no problem with my CGI nor in my Ruby application because it...

Redirecting and routing ruby on rail

I'm still new to ruby on rails and I'm currently having a issue with routing and redirecting. I have two controllers "candidate" and "survey". I'm currently viewing "canidate/editEmail.html" http://www.otoplusvn.com/TherapistSurvey/candidates/editEmail/2 Once the submit button is clicked, the candidate's method for updating the ema...

How to define a method some how like the 'yield' ( I mean, automatically catch the block)?

If I need to define a method called 'yields' which will call yiled 3 times: def yields 3.times do yield end end And then I will use it in an other method: def call_me_3_times yields end In the console or irb: >> call_me_3_times { puts 'me'} # => Cause error => LocalJumpError: no block given (yield) from (ir...

referential integrity in rails

So, I just came across the fact that rails does not support referential integrity regarding foreign keys and was fairly surprised. So, what's the best way to manage this? Is there a "rails" way for dealing with referential integrity? Ideally the app should not have to deal with all this; the db should. I was looking at plugins like fore...

Ruby model with an array as an attribute

Hello, I am currently trying t implement a model to simplify graphical chart creation. However, one of the attributes must be an array of attributes. For example: "Chart_Series" has a "name" which would be a string and a data field which would be separated by dates which is an array of arrays [[Date1, Value1],[Date2,Value2],[Date3,Value...

Send GZipOutputStream XML using Blackberry to RoR web server

Hi, I tried to post data from Blackberry device using GZipOutputStream, on the server we use Ruby on Rails to capture the request. Somehow the request contain unknown characters, it looks like this : Parameters: {"format"=>"xml", "action"=>"inspections", "\030\031\000��bbrequest"=>"<?xml version=\"1.0\"?>\r\n<rqsCreateInspection><verA...

rails check if page is translated

Hi guys, I am writing a helper for our app that will return if the page is not in english. At first this was my check: !params[:lang].nil? || !cookies[:lang].nil? || !session[:lang].nil? || !session[:locale] || !params[:locale] (i looked at params, cookies, and sessions) if any of them wasn't nil, then I'd immediately conclude that th...

Rails: how does member of collection get called in option_groups_from_collection_for_select

Hi everyone, Im about to figure out how to call a function with one member of the collection I want to thisplay in a option_groups_from_collection_for_select. The sample is as following: option_groups_from_collection_for_select(@categories, :children, :name, :id, :name, 3) In my code I need to replace the :name tag with a function t...

Accesing hash keys and attributes from the view

Hello, in an attempt to create a model with an array as an atribute, i ended up creating an array of hashes like so: data1 = {} data1[:name] = "Virtual Memory" data1[:data] = @jobs.total_virtual_memory data2 = {} data2[:name] = "Memory" data2[:data] = @jobs.total_memory @data = [] @data << data1 @data...

SEO for Rails site, now or later?

My freelance web developer is developing a site on Ruby on Rails. Currently the URL structure is http://abc.com/all?ID=category Example: http://abc.com/all?3=CatA I requested him to structure the URL according to categories, such as http://abc.com/CatA/3-page-title but he refused cos it was too much work and cost involved as he is ...

Is it a good idea to use a foreign key to reference 2 or more tables?

Hi, Ruby on Rails ORM(object relational mapping) has a thing call polymorphic associations that allow a foreign key to be used to reference 2 or more other tables. This is achieved by creating an additional column called "type" that specifies the table with which the foreign key is associated with. Does this implementation have a name f...

Overriding public-directory in Rails 3?

I'm building a template system for a CMS in Rails 3, with each template placed in {application_root}/templates/{template_name}/. For each template I would like to have a public-directory that overrides the standard one. How can it be done? ...

How to display validation error in Rails during an update operation ?

Hi, I am having a form and I am trying to save something. Whenever I hit the save button, I am running an update query in the controller. Everything works fine. I have put a validation in place for one of the text fields which takes text lengths of minimum 5. The error appears while I create the entry. However, when I try to just updat...

spec rake task for daily cron

I have a series of rspec tests which I use to make sure some web scraping services I wrote are still valid. I have all of these inside a GEM which my rails app requires and I'm not quite sure how to embed a rake task of spec for an external gem? I'm not sure that is at all clear, I have a gem w/rspecs: Gem w/rspecs MyApp I would lik...

Rails XML builder

I have controller action in my rails application to output XML which in turn is used to generate a FusionChart. I am using a builder template for generating XML. Below is the code that is in builder template. xml = Builder::XmlMarkup.new xml.chart(:palette=>'2', ....) do for item in @domain_data xml.set(:label=>item[:domain],...

Rails: multiple names for a resource

Is there an elegant way of having multiple names for a single resource. We would like to give the user a choice via a setting of what they would like to call their "things". I.e. products, items, services whatever. So far I can only think of using multiple routes to a single controller: resources :products resources :items, :controller...

Rails unit testing associations

Should I write unit tests for my associations? I haven't found many good resources on how and whether to do the testing. I also see/hear some opinion that it is okay to not test your associations (belongs_to and has_many) as they are already tested in rails. And there is another view that says, if it code you write, it is code you test...

Rails order by associated object number

Hey, The title of this question might be a bit off but its the closest I could get to what I am trying to do. I have a Products model which has_many Comments. I am looking to come up with a way to grab the top 10 Products with the most comments. Is this possible? At the moment I have: Product.find(:all, :limit => 10) This gets me...

Uploading & Unzipping files to S3 through Rails hosted on Heroku?

I'd like to be able to upload a zip file to my Rails application that contains a number of images. Then I'd like Rails to unzip that file and attach the images inside to my Photo's model via Paperclip, so that they are ultimately stored on my Amazon S3 account (configured through Paperclip). I'd like do do this all on my Rails site host...

Handling ambiguous routes in Rails

Here's my dilemma: I have two types of routes which are semantically very different, and should go to different controllers. ny/new-york/brooklyn/cleaners # should go to a list of cleaners for a neighborhood ny/new-york/cleaners/mrclean # should go to an individual cleaner's page Note that "brooklyn" and "cleaners" here are just exam...