ruby-on-rails

What's the best guide to Rails routes for the totally confused?

I've been learning Rails but routes continues to confuse the heck out of me. The thing that makes it most confusing, I think, is that the routes you define are sensitive to where they are defined in your routes.rb file relative to other routes. Has anyone come across a nice simple guide that sums things up well? ...

Rails 2.3 session

Hi, I am developing a rails 2.3.2 app. I need to keep session_id for an order record, retrieve it and finally delete the session_id when the order is completed. It worked when I used cookies as session store but it doesn't for active_record store. (I restarted my browser, so no cache issue.) I know rails 2.3 implements lazy session loa...

Any Rails Plugin/Gem available to facilitate users to import their profile info from LinkedIn?

Any Rails Plugin/Gem available to facilitate users to import their profile info from LinkedIn? ...

How to test a rails model that accepts nested attributes with Cucumber

How do you test a model Topic that accepts nested attributes for an Image? Given /^I have topics titled (.+)$/ do |titles| path ="#{RAILS_ROOT}/features/upload-files/" image = File.new(path + "image.jpg") titles.split(', ').each do |title| Topic.create!(:title => title, :image => File.new(image) ) # this doesn't work! ...

Disable the text box from being accessed by the user in calendar_date_select

I have a date picker <%= calendar_date_select_tag "from_date", nil, :embedded => false, :year_range => 10.years.ago..0.years.ago, :valid_date_check => "date < (new Date()).stripTime()" %> The problem is as it is not embedded a text box appears and it makes the users to change it. How can I make it off so that only this datepicker can ch...

how to delete rails log file after certain size

Hello, I have a daemon that runs constantly which fills up the log file(development.log or production.log) pretty quickly. What is the best way to delete the log file after certain size or delete the portion before certain day. Thanks, Tam ...

How to access and submit related polymorphic models in the same form, in Rails?

Suppose I have 3 models, Car, Motorcycle and Truck, and for each I have to enter a bunch of stuff, such as a list of known previous owners, traffic tickets, license plates, etc. So I created a model for each (PreviousOwners, PreviousPlates, etc) and set up polymorphic associations for the related models. The problem is, how can I enter ...

LocalJumpError (Ruby on Rails)

Hi I have searched/Googled around but I'm struggling with the following problem. I am building a Rails 2.3.2 application and one of the requirements is to calculate the median of an array of results. I am using code for calculating the median from the Ruby Cookbook but keep running in to a problem with receiving an error 'LocalJumpErr...

rails accepts_nested_attributes_for :reject_if not working

I gave on trying to override the autosave parameter since I think it can't be done. I moved the has_shipping_address from the Order to the ShippingAddress model and now I have: #the models.. class Order < ActiveRecord::Base belongs_to :billing_address belongs_to :shipping_address accepts_nested_attributes_for :billing_address ...

Subquery in Rails report generation

I'm building a report in a Ruby on Rails application and I'm struggling to understand how to use a subquery. Each 'Survey' has_many 'SurveyResponses' and it is simple enough to retrieve these however I need to group them according to one of the fields, 'jobcode', as I only want to report the information relating to a single jobcode in o...

What is a reliable method to record votes from anonymous users, without allowing duplicates

First of all, I searched as best I could and read all SO questions that seem relevant, but nothing specifically answered this. This is not a duplicate, afaik. Obviously if anonymous voting on a website is allowed, there is no fool proof way to prevent someone voting more than once. However, I am wondering if someone with experience can...

self join table - performance/other implications

Are there any performance/other implications in having an object relates to itself? (self join) Consider the following example: PEOPLE (table name) belongs_to :profile, :class_name => 'Person', :dependent => :destroy id login password first_name last_name profile_id This question is party stemmed from another question posted at http:...

Is it meaningful to override the '==' method in ActiveRecord subclasses?

Rails' ActiveRecord::Base class defines an == method that returns true if the objects are identical or they have the same ID. I've overridden == in a couple of my Rails models to allow for more meaningful equality conditions. These work when I compare objects directly (e.g., through script/console), but if I do something like my_array_o...

Dynamic Paths in Helper

hello, Im trying to create a helper method for my admin links. in quite a few views i have the code <% if current_user %> <%= link_to "Edit", edit_model_path(model) %> <%= link_to "New", new_model_path %> <%= link_to "Delete", model, :confirm => "Your a Noob", :method => :delete %> <% end %> that only display these when logged in. ...

What should I ask the previous development team during my only (1-3hr) meeting?

There is Ruby on Rails (1.8, 2.3.2) project. First version of project was made by some organisation. I will implement next versions of this project without any help from this organisation. I will be able to talk with developers from previous development team during meeting (1-3 hours). Project statistics: ~10k LOC, 1.0/0.6 code to test ...

How do I redirect multiple actions to a single action while maintaining DRY?

I have an OptionsController, which contains an action account. The corresponding view has three forms, which post to three different actions, update_profile, update_user and change_password. Each action runs and then should redirect back to action, where the view is set up again and rendered. I was trying to be DRY and create an after_f...

Ultrashpinx: Strange issue - all entries returned when searching for model name

Hi, I'm using Ultrasphinx for a fulltext search in a rails app. I encountered a very strange behavior. When I search my User model and search for q = "user" I get all the users as a result, even though some of them havent got the term "user" in any field. What is going wrong here? Heres my setup: # models/user.rb class User < ActiveR...

MySQL Full-text search in Ruby on Rails

I am trying to implement a basic full-text search with MySQL. I wrote this migration: def self.up execute 'ALTER TABLE photos ENGINE = MyISAM' execute 'CREATE FULLTEXT INDEX fulltext_photos ON photos (place, info)' end def self.down execute 'ALTER TABLE photos ENGINE = InnoDB' execute 'DROP INDEX fulltext_photos ON photos' en...

How does one collect rcov-style information on the processing of erb templates?

I'm using rcov on a set of tests autogenerated from my rails routes to collect information on dead code (code which is never called in the application). This set up already generates enlightening results for controllers, models, helpers, and lib code. Unfortunately rcov does not track code coverage in erb templates, which makes sense a...

Restful Rails controller for Flex front end

So I have an existing rails app that I've been asked to retrofit to support a flex client. Since I don't really want to muck around with the existing controllers and routes, I thought the best way to accomplish this would be to create a subdirectory in app/controllers called flex and put in some additional controllers in there to handle...