ruby-on-rails

Why is Rails is trying to rerun migrations on production?

On my server when deploying the app for the first time, I ran rake db:setup which loads my entire migration history from schema.rb. Now I have more stuff I want to add, but when I run rake db:migrate on my server I realize it's trying to run my very first migration, which is failing since the table obviously exists. Examining the schema...

How can I create activerecord models that are subsets of a certain model?

I've seen this before but can't figure out what the correct term is. Basically, I'd like to create models for a specific subset of table data. E.g. (these are not the real classes) class Person < ActiveRecord::Base class Man < Person <something here> :gender => 'male' ...

What to ignore in a Mercurial .hgignore for a Ruby on Rails app

I created a hello world app with rails HelloWorld command. I ended up with many directories: app config db doc lib log public script test tmp vendor Should all this be under sources control? What would be a good default .hgignore file for a Ruby on Rails app folder? ...

How do I aggregate activerecord model data for a specific time period?

I'm collecting data from a system every ~10s (this time difference varies due to communication time with networked devices). I'd like to calculate averages and sums of the stored values for this activerecord model on a daily basis. All records are stored in UTC. What's the correct way to sum and average values for, e.g., the previous ...

Using a helper method in a mailer that is defined in a controller

The helper method current_user is defined and made available as a helper in ApplicationController like this: class ApplicationController < ActionController::Base helper_method :current_user def current_user return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session....

How to sort objects in a many-to-many relationship in ruby on rails?

I've been trying to deal with this problem for a couple of hours now and haven't been able to come up with a clean solution. It seems I'm not too good with rails... Anyway, I have the following: In code: class Article < ActiveRecord::Base has_many :line_aspects has_many :aspects, :through => :line_aspects #plus a 'name' field ...

How do I load Formtastic to test it?

I am using Rails 2.0.2 and following Github installation instructions: 1. add as gem source ie "gem sources -a http://gemcutter.org/".....ok 2. install gem ie "gem install formtastic"....gives error, could not find formtastic locally or in a repository I am learning Ruby on Rails and have no knowledge of gems ...

Rails and MongoDB with MongoMapper

I'm new to Rails development and I'm starting with MongoDB also. I have been following this Railscast tutorial about complex forms with Rails but I'm using MongoDB as my database. I'm having no problems inserting documents with it's childs and retrieving the data to the edit form, but when I try to update it I get this error undefi...

Should I skip authorization, with CanCan, of an action that instantiates a resource?

I am writing a web app to pick random lists of cards from larger, complete sets of cards. I have a Card model and a CardSet model. Both models have a full RESTful set of 7 actions (:index, :new, :show, etc). The CardSetsController has an extra action for creating random sets: :random. # app/models/card_set.rb class CardSet < ActiveRe...

Merge 'tileset images' into a single background using Ruby

I have a table that is 26 squares by 26 squares. Each square is going to be 30px * 30px. Given the tiles upper_left.png upper_right.png upper_wall.png and: left_wall.png right_wall.png and: bottom_left.png bottom_wall.png bottom_right.png I aim to comprise a background that is 780px*780px. For the sake of speed and to preven...

Store CSPC and UPC Codes in Rails

What the best way to store CSPC and UPC codes are in Rails? I used integers with SQLite, but had overflow issues when moving to production. I've since switch to strings, but am not sure if a better generic datatype (needs to support SQLite, MySQL and PostgreSQL). Thanks. ...

deploment on EC2 using poolparty and chef server

hi, does anyone have done the rails application deployment on EC2 using poolpary gems and chef server(not chef solo).please share your experiences if you know some blogs or code links(except poolpartyrb.com and related to it). the poolparty script must be able to launch an selected AMI instance with two EBS blocks(data and DB) use one ...

Generic Rails Route Representation?

Given one or more instances of a model (AR or DM, whatever). Is it possible to generate the route in the requirement form, by which I mean "/foos/:id" Given the route: resource :foo do resource :bar end generate_route_method [@foo,@bar] -> "/foos/:id/bars/:id" I'm not talking about #foos_path or #polymorphic_path, rather, literall...

How do you change the default collation of MySql for rake db:create:all in rails?

In my rails app I am running rake db:create:all in order to create the databases and I am prompted that the collations do not match. Is there a way to change the default MySQL collation? If not what is the best way around this? Thanks ...

Rails: combining multiple find requests

What I want to do is something like this: searchid = 4 while searchid != -1 @a += A.find(searchid) @b = B.find(searchid) searchid = @b.parentid end The problem being the line @a += A.find(searchid) The error being something like NoMethodError: undefined method `+' for #<A:0x173f9a0> So, how do you combine multiple 'find...

First step in Ruby on Rails

Hi.. I am going to learn Ruby on Rails (ROR) , can any one help me how to write a "hello world" program and How can I run the program. ...

Is there anything "objective" about C# 4.0, or ruby-like?

This is a very "high-level" question. I'm looking for insight into this problem that c# has. It has so many features that it supports almost ANY task, alas there are alternatives that are better suited for some tasks. With the advent of MVC(old news) + ruby, people are starting to have "fun" AND getting things to work. C# seems like a...

Can't find data_warehouse ruby gem.

I am working on a project and i was trying make it up and running in my local machine. But unfortunately the app is using a gem data_warehouse( found gem 'data_warehouse', '= 1.5.2' in environment.rb), I tried to look for this gem but can't find this gem, I was unable to run the application because of this. I never used data warehousing ...

Rails: change URL response format

How to easily change the format of URL in a right way: /comment/10.js?param1=6 to /comment/10?param1=6 Preferrably with some URL library or so, not with regexps. Use case: redirect back with request.request_uri saved in session. ...

Rails Multiple Checkboxes with Javascript Dynamic Select

Hi, I have followed the Railscast episode 88 to implement a set of dependant drop down menus. In the students->new view, when the student's year is selected, the javascript figures out which courses are available to that year and offers the selection in a new drop down menu. My javascript erb file is here: var courses = new Array();...