ruby-on-rails

Rake Abort Error with no answer other than head to the wall . Repeat if necessary.

I am the intrepid little programmer that could. I began programming rails five weeks ago and I have been stuck on the same error for that entire time. It goes like this. I have mysql application installed, have the latest rails (2.3.5), ruby (1.8.6), and mysql (5.1.40). I created a perfectly beautiful database and table with content in ...

factory_girl association validations

I have an issue where I have a parent model Foo, which both has_many :bars and has_many :bazes. Finally, I also have a join model BarBaz which belongs_to :bar and belongs_to :baz. I want to validate all bar_bazes so that its bar and baz both belong to the same foo. But I can't seem to figure out a way to define a factory for this mode...

Singleton resource - how to delete a different resource than the singleton

In routes.rb I have map.resource :user In one of my templates I want to link_to 'delete', some_other_user, :method => :post I was hoping this would generate a url like /user/#{some_other_user.id} but instead get /user.#{user.to_s} The only solution I've found is to add a new route map.delete_user 'users/:id', :controller => 'use...

Ruby BigDecimal Round: Is this an error?

While writing a test with a value that gets represented as a BigDecimal, I ran into something weird and decided to dig into it. In brief, '0.00009' when rounded to two decimal places is returned as 0.01 instead of 0.00. Really. Here's my script/console capture: >> bp = BigDecimal('0.09') => #<BigDecimal:210fe08,'0.9E-1',4(8)> >> bp.ro...

Rails Question: Why can I do these two javascript calls separately but not together?

On the homepage of my web app I'm implementing pagination with ajax as well as an autocomplete search. The script I used for the ajax pagination is here: http://wiki.github.com/mislav/will_paginate/ajax-pagination The script I used for autocomplete search is detailed in my own answer to this question: http://stackoverflow.com/questions...

Finding the next ActiveRecord model object in the database using given object

I have an ActiveRecord model object @gallery which represents a row in the Galleries MYSQL table. Is there a way for me to ask @gallery to give me the id to the next gallery object in the table? The obvious way for me to do this is to : @galleries = Gallery.find(:all) index = @galleries.index(@gallery) @nextgallery = @galleries[index+...

rounding float in ruby

hello, I'm having problems rounding. I have a float, which I want to round to the hundredth of a decimal. However, I can only use .round which basically turns it into an int, meaning 2.34.round() = 2. Is there a simple effect way to do something like 2.3465 = 2.35 thank you ...

Modal audio player that continues to stream without interuption when a user browses to another page (of same site)

I'm looking for a media player (audio) that I can embed in my website (a rails app) to allow streaming audio which doesn't stop when the user goes to another page of my website. Ideally it would be modal. I've tried using the YUI Media Player but the audio reloads when users move away from the homepage and most users don't think to pla...

Passenger/mod_rails fails to initialize in Fedora 12 when starting Apache

I am in the process of setting up a server to run a Ruby on Rails application on Fedora 12, using Passenger. I am at the stage where I've installed Passenger, set it up as prescribed, but get the following errors when I restart Apache: [Wed Jan 13 15:41:38 2010] [notice] caught SIGTERM, shutting down [Wed Jan 13 15:41:40 2010] [notice]...

Ruby on Rails: RSpec and Acts As Audited (disabling acts_as_audited while testing?)

Hi everyone. I've been getting an error, which I think could be solved by disabling acts_as_audited when running tests, or at least stubbing current_user in audit sweeper. The error is below. What do you think I should do? NoMethodError in 'Order should create a new instance given valid attributes' You have a nil object when you didn't ...

HABTM, or multiple belongs_to?

I'm teaching myself Rails, and as a test project I'm mocking up a simple question/answer app similar to stackoverflow. In my simplified version I have: questions answers users (the authors of questions and answers) I get that answers belong to questions. What's the proper relationship between users and questions? What's the proper re...

Thinking Sphinx not indexing newly added records

I am using sphinx to search on 2 models along with their associations. I am using delta indexing. Things work fine on my dev box in dev mode (Ubuntu). However, on staging box production env, when I create new records, I need to build the index again in order to make the newly created records searchable. Even weird is that when I create r...

Rails index of an association

I find myself requiring this. Assuming cart is a model which has a list of users. def index_of_item cart.users.each_with_index do |u, i| if u == current_user return i end end What's an easier way to get the index of an association like this? ...

Is Grails (now) worth it?

I know this is a duplicate, however, the Grails world has moved on considerably since that question was asked more than a year ago, as has the IDE support in Eclipse, so please don't just blindly close it. I thought the answer was yes and have embarked on a new project with Grails 1.2.0 and have flirted with the Groovy/Grails bits of ...

Rails application needs access to a tmp directory

I'm using the fleximage plugin with a rails application. It throws an error message because it doesn't have access to the tmp directory. When I chmod 777 the tmp directory everything works fine. But if I chmod 666 it doesn't work. What are the proper permissions for folder that needs to be accessed by rails/apache? if chmod 777, am I o...

What user am I currently logged in as?

I am using debian. Is there a command that will show me what user I am currently logged in as? I want to use this command in a rails application that I'm building for debugging purposes. ...

Best way to save datetime via api in rails.

I have requirement to save datetime (visited_at) attribute via api like POST localhost:3000/visit, but the problem is I don't know how to handle time zone. I have see the explanation about rail time zone support here, but that when you create it through rails form. What I want to know if there is a way to handle this through my own api. ...

Multiple one to many relationships using the same 2 tables in ruby on rails?

I have a database with 2 tables; Users and Revisions. Revisions has multiple one-to-many relationships to the users table, for example created_by, verified_by, published_by (each field being a foreign key user id). How would I go about defining this relationship in my Rails models? ...

More virtual hosts on one rails application

I would like to access one rails application through more virtual hosts. The different virtual hosts would differ in the database, images, stylesheets and in some cases the layout of the views. What do you recommend for realisation of serving multiple applications by one rails code, which is accessed through different virtual hosts? Edi...

Validates_uniqueness_of does not work when doing a large Transaction

I have a validate_uniqueness_of :field inside my ActiveRecord model. When i do a single create/update it works nicely but i have to do some large batch creation from csv files inside a Transaction When i am in the transaction the validate_uniqueness_of does not detect the error and the model is saved! ...