ruby-on-rails

Seamless deployment in Rails

I would like to seamlessly upgrade my Rails app: Meaning: If no migrations need to run I would like to transparently upgrade the code and have no requests go 404 during the deployment. This is hard I would like to have some process that can upgrade the database seamlessly and during that time just hold back on the web requests (que...

Best IP to Location for Ruby on Rails

I was wondering if anyone had any experience with a good plugin/gem that pulls city and state from the IP. I've tried the one built into GeoKit but it's terrible. I don't mind paying for it as well but I would prefer free. ...

Blueprint, Sass and BrowserCMS

I like quite much browserCMS. And I also favour sass and blueprint. I would like to make these things to play together. Although I read somewhere brosercms can sass and blueprint, it is not obvious for me how to really have it there. Can you recommend me steps how to reach this? ...

Testing concurrent Rails-App with Sqlite

I'm working on a Rails application that is multi-threaded. A user can start a tool from a web-form that may take several minutes to finish and that writes status-updates in the database (the tool is started in a separate thread). The user can check the current status on a status-page that refreshes itself regularly and reads the current ...

globalize2 with xml/json support

I'm implementing a distributed application, server with rails and mobile clients in objective c (iPhone). To enable internationalization, I use the rails plugin 'globalize2' by joshmh. However, it turned out that this plugin does not translate attributes when calling to_xml or to_json on an ActiveRecord. Does anyone know of a workaround...

Transform Ruby-on-Rails code to PHP

This may sound odd but a right answer might save me hours of coding. I have found a ruby-on-rails class (~10 files, ~1000 lines total) that serves a specific purpose (payment gateway integration). However, I am not familiar with ruby at all and need to use that class in a PHP application. I am wondering if there is a program that can per...

[Rails] How to associate a new model with existing models using has_and_belongs_to_many

I have two models with a many to many relationship using has_and_belongs_to_many. Like so: class Competition < ActiveRecord::Base has_and_belongs_to_many :teams accepts_nested_attributes_for :teams end class Team < ActiveRecord::Base has_and_belongs_to_many :competitions accepts_nested_attributes_for :competitions end If we a...

How can I delete the tag from the tag list of the act_as_tagg plugin?

I have tried to destroy tags from the given code but it's not working. How can it be accomplished? @tag = Tag.find_by_name(params[:name]) @tag.destroy render :update do |page| page[:divtag].innerHTML = render :partial => "controls/tag_list" end ...

Fetching second level model with rails active record

Hello, I have a relationship in which a post belongs to the city which inturn belongs to a state like: class Post < ActiveRecord::Base belongs_to :city end class City < ActiveRecord::Base belongs_to :state end Now i want to find all the posts along with the their cities and the states to which the belong to. I w...

Selecting table entries where a given date is between the :start date and :end date

I have an object that has a start date and an end date, in order to represent the time that the object is valid. Given a date, is there a way to only select those objects that have valid ranges that contain the date? I tried fiddling with between, but couldn't get the syntax right. Thanks! ...

Using :collection and :include_blank in Formtastic. How to do it?

I use the superb Formtastic plugin for Ruby on Rails. Does anybody know how to include a blank (option), when using a custom collection? When I try: <%= f.input :organizations, :collection => Organization.all(:order => :name), :include_blank => true %> I get the select box with the collection, but NOT a blank... ...

Rails: Limiting daily user login count by IP address?

Is there any way to limit a user's login access to only, say, 5 IP addresses daily? Such that if a user account tried to login in the same day from a 6th different IP address, they would be denied. I would like this restriction to reset at the end of the day, however. If Authlogic doesn't provide a way to track this out of the box, what...

Adding callbacks for model classes in separate file (RoR)

I have a Message model class (which inherits from ActiveRecord::Base). For a particular deployment, I would like to have a separate file which modifies Message by adding a callback. So, instead of doing: # app/models/message.rb class Message < ActiveRecord::Base before_save :foo def foo puts 'foo!' end end I would like to b...

How to check for a role

Hi, I'm a rails noob and first time poster here and am using declarative authorization in order to implement role base access restriction in a small timesheet app I am writing. In one of my views, specifically the index.html.erb for my time_registers needs to display more information if the user who is logged in has the admin role ass...

How to protect I.P. in Rails code when outsourcing to dispersed developers?

I am thinking of outsourcing development of a Rails app to dispersed developers overseas. But I am concerned that I would be exposed to having the entire system stolen, with the stealee setting up a parallel SaaS service. Is it possible/practical to somehow split up the code or partition the app so no single developer gets access to all ...

Associate User with Account in Rails

Hello, I'm very new to Rails (this is my first project). I have a situation where an account can have many users and projects, and users can have many projects and vice versa. I have authlogic running on my Users model. I'm confused about where to go after this. After creating a new user, how do I pass the user information into account?...

Creating a set number of child objects from a parent's form

Thanks to http://stackoverflow.com/questions/2020673 and "Agile Web Dev", I know how to have multiple models in a form using fields_for. But I'm tearing my hair out over this one. Suppose I have a model Person. Person has a name attribute, and has_many :foos. The Foo model, in turn, has a colour attribute. Furthermore, I know that each...

why is this rails association loading individually after an eager load?

I'm trying to avoid the N+1 queries problem with eager loading, but it's not working. The associated models are still being loaded individually. Here are the relevant ActiveRecords and their relationships: class Player < ActiveRecord::Base has_one :tableau end Class Tableau < ActiveRecord::Base belongs_to :player has_many :table...

De facto approach to sorting with will_paginate

I'm using the will_paginate gem to display a collection in a paginated fashion. Now I'd like to have sorting functionality on the columns of the list in the view. I've added my own custom mechanism for establishing this, but it left me wondering if there isn't a standard way of doing this, leveraging the simplicity and elegance of will_p...

change emacs ruby-mode indent to 4 spaces

From a previous post I got Ruby mode working in emacs. This is working great. http://stackoverflow.com/questions/2078079/setting-up-emacs-file-for-mac-ruby-development Our company uses 4 spaces for indents though instead of the default 2. I am having difficulty getting this to work. Here is my .emacs file (add-to-list 'load-pat...