ruby-on-rails3

Rails misbehaving wrt Postgres SERIAL NOT NULL column

I am developing a (currently) Rails 2.3.x application with a PostgreSQL 8.4 database backend. In my Rails application, I have a model corresponding to a database table that has two columns of datatype SERIAL and set as NOT NULL. I have one of these columns set as the primary key in both Rails and as a PostgreSQL constraint. Table defin...

Rails 3 - collection_select - Understanding PROMPT ?

I'm building a form to allow a user to CRUD a project permission. .... <% roles = Role.all %> <%= f.collection_select :role_id, roles, :id, :name, :prompt => true %> Problems with the above, while it renders: If a value matches, it shows that in the dropdown as selected, which is good. Problem, is if a user is set as ADMIN. It's ea...

Paperclip - Default Style per Style? Possible

Hello, I'm using paperclip, and have several styles: :styles => {:large => "300x300>", :medium => "150x150>", :small => "50x50>", :thumb => "30x30>" } The issue is default_stype, only applies to one of the sizes... :default_style => :thumb, :default_url => url here.... How can I set default_stypes for each style type? so if I call:...

How to upload audio files using Paperclip in Rails 3?

I'm very new to Rails. Basically, I have a Sound model that uploads an audio file(wav) and store it somewhere on the local machine (for testing). How to set it up using Paperclip? I googled but unfortunately most of the tutorials are about image uploading:-( Any inputs are greatly appreciated. ...

How add hash parameter to url using redirect_to?

How add hash parameter to url using redirect_to? For example: http://localhost/products/#{page:2} ...

rails3-generators does not add any generators

Here is my Gemfile gem 'rails', '3.0.0' ... gem 'haml-rails' gem 'jquery-rails' group :test do gem 'shoulda' gem 'rspec' gem 'rspec-rails' gem 'factory_girl' end gem 'rails3-generators', :group => :development ... I run bundle install/update. And then not all new generators (from rails3-generators) are added. haml generators...

virtual attribute with dates.

I have a form which i'd like to simplify. I'm recording a startdate and an enddate, but would like to show the user only a startdate and then a drop down with number of days. But I'm having problems with my model and storing it correctly. The first part works. def date=(thedate) #puts the startdate in the correct format... ...

An easy way to get list of view layouts

I need an easy way to grab layouts that are found in /app/views/layouts. I technically can go in there from Rails.root and grab all files I can, but I'm sure there's a better way. Rails knows where to look for layouts and what extensions are ok. I tried to dig through actionpack but nothing popped out at me. Thanks ...

Arel causing infinite loop on aggregation

I have trouble with using Arel to aggregate 2 columns in the same query. When I run this, the whole server freezes for a minute, before the rails dev-server crashes. I suspect an infinite loop :). Maybe I have misunderstood the whole concept of Arel, and I would be grateful if anybody could have a look at it. The expected result of th...

Parsing a complex URL in Ruby

Hello, I'd like to retrieve the value of 'q' in this URL: http://www.google.com/url?sa=X&amp;q=http://nashville.broadwayworld.com/article/Just_in_time_for_Halloween_Circle_Players_does_JEKYLL_HYDE_20101013&amp;ct=ga&amp;cad=:s7:f1:v1:d2:i0:lt:e0:p0:t1286988171:&amp;cd=yQoOdKUFTLo&amp;usg=AFQjCNEg2inHF8hXGEvG-TxMQyMx7YGHkA if I use thi...

ActiveModel::Naming attributes definition

Dear all, I'm working on a rails3 app and I'm a little bit confused with Active Model. Here is my model : class MyClass include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_accessor :foo, :foo1, foo2 def initialize(attributes = {}) attributes.each { |key, value| send "#{key}=", va...

Pass instance or local variable from layout to view in Rails

I'm trying to set up a rather complex form using form_for. This form needs to be in multiple views, where some fields would be available across all actions and other fields are specific to each individual actions. I thought that in order to save myself code duplication, I would use a layout to render the general part, like this: # layo...

Do you do this in every step definition ? "Given that I am logged in"

I am new to cucumber. And for most of the site's functionality, you have to be logged in. So when writing cucumber, do you write, given that I am logged in for every step definition? ...

Do all join tables have tables?

For example I have a comments models, and I have a post model, but comments can comment on other comments. So it seems I need a join table I'll call commentables. To create this, do I really need to create a commentable table with a post_id and a comment_id ? Or can I do something like this without one : has_many :comments...

rails 3 has_many :through record save error

I'm not exactly sure what my problem is, so this question may require some more clarification, but here's what seems to be most relevant: I have a has_many :through and the join model has some fields that aren't foreign keys. When I build the models up and try to save I get a validation error on the non-foreign key fields from the join...

Route fails from one page, succeeds from another

I have one bit of javascript that fires off an ajax request, the result of which gets loaded into a popup dialog. This is the same javascript in all cases, but in one case, the route fails. From the new_army_list page: Started POST "/army_lists/preview" for 127.0.0.1 at 2010-10-13 21:42:15 -0400 Processing by ArmyListsController#previ...

Rails 3 has_one/has_many question

I am writing an application that contains a database with several tables and joining tables and so forth... the two I am working with currently (and am stumped on) are my pages table and my templates table. Now a page can contain only one template, but a template can have many pages. Model for Page: class Page < ActiveRecord::Base h...

Rails Model: Name -- First, Last

I'm fairly new to rails, working on a Rails 3 app with a Profile model for users. In the profile Model I'd like to have a "name" entry, and I'd like to be able to access logical variations of it using simple syntax like: user.profile.name = "John Doe" user.profile.name.first = "John" user.profile.name.last = "Doe" Is this possible, o...

Don't escape html in ruby on rails

Hello, rails 3 seems to escape everything, including html. I have tried using raw() but it still escapes html. Is there a workaround? This is my helper that I am using (/helpers/application_helper.rb): module ApplicationHelper def good_time(status = true) res = "" if status == true res << "Status is true, with a long ...

Where should I put CONTROLLER helper methods?

I know that "helpers" are usually for views/templates. But say I have a helper method that I want to call from different controllers. Where should this file go? I was thinking of creating a helper module in the "models" folder but I'd like to know if there's a "correct" way to do this. ...