ruby-on-rails

Rails cache_counter not decrementing?

I have a cache counter setup for a Posts class on the comments field. Posts have many comments, and a comment belongs to a post. If I add a new comment to a post and save, the counter gets incremented, but if I delete an individual comment, the counter is not touched. Is this not provided automatically, or do I have to roll me own decr...

howto clear all rails sessions?

hello , here is my code: if session[:firsttimestart].nil? else @firsttime = false end if @firsttime == true initglobals() end session[:firsttimestart]=false the problem is when i turn off the server and come back to the application the session[:firsttimestart] is still false , it somehow stores this variable in my system withou...

Test::Unit 2.x tests run from rake but fail from autotest

I'm having problems running my Rails unit tests via autotest using Test::Unit 2.0.6. Running tests via rake test:units works perfectly, but when I run the tests from autotest, I get this: /Code/projectdir/vendor/rails/activesupport/lib/active_support/dependencies.rb:105:in `const_missing': uninitialized constant Test::Unit::TestResult:...

Setting up custom domain on Heroku with CNAME redirect for www subdomain

I'm using Heroku, and have added a couple custom domains for my app, i.e. myapp.com and www.myapp.com My DNS at GoDaddy has three A records for '@' pointing to three separate Heroku IPs, and a CNAME for the 'www' subdomain that points to proxy.heroku.com What I want to do is redirect any traffic to www.myapp.com to myapp.com. I tried s...

Migrating from clear password storage to authlogic

Hi ! I'm currently working on a Rails app which stores plain clear passwords (...). So I'm migrating to Authlogic authentication with a 'standard' SHA512 encryption. I did that which works fine : #file /models/user.rb class User < ActiveRecord::Base acts_as_authentic { |c| c.transition_from_crypto_providers = [MyOwnNoCrypto, Au...

How to dump the database to yaml file with content '<% abc do %>ddd<% end %>'?

In my database, there are some text content, one of them is: <% abc do %> ddd <% end %> When I dumped it to yaml with to_yaml(), it is like: content: |- <% abc do %> ddd <% end %> And then, when I use rake db:fixtures:load, such error occurs: The exact error was: NoMethodError: undefined method 'abc' for main:Object...

How to populate select box from db query

Hi, I am trying to populate a ruby on rails select box from a database query, the data comes from 3 tables. My query @data = Session.all :include => { :term => :courses } Object !ruby/object:Session attributes: created_at: 2010-06-17 22:12:05 term_id: "15" updated_at: 2010-06-17 22:12:05 id: "3" course_id: "1" attributes_cache: ...

Disable/configure HoptoadNotifier per controller

How could I disable or configure the HoptoadNotifier per controller? Background is that I configured the notifier to report "Method not allowed" exception, eg this is raised when an action is accessed with GET instead of POST. But I have an autocomplete controller which is scanned by bots (probably to find exploits) by sending GET reque...

has_many, belongs_to association where has_many associated model has two alias fk in belongs_to associated_model...

I have a User model that has many fights. Fight belongs to User. There are two foreign keys in the fight table that reference back to the user PK -- challenger_id and challengee_id. The trick is how do I write the has_many association on the User model so that it returns fights where user_id = challenger_id or challengee_id? ...

Creating classes for nested blocks in Ruby

Hi! I want to reformat some helpers in my Rails views. I want to archieve a syntax similar to: <%= box :option => 'value' do |b| b.header "Header of box #1" %> Content of Box#1 <% end %> The b.header call is optional. How would I structure my code to allow this? I guess it's something similar to fields_for in Rails. Tha...

How to Print Rails Source Code?

I'd like to read the Rails 3 source code on printed paper (and preferably in color). For example, xv6 (http://pdos.csail.mit.edu/6.828/2009/xv6-book/index.html) did a nice job printing their code (http://pdos.csail.mit.edu/6.828/2009/src/xv6.pdf). It even has line numbers and an index. The only thing I would like to add is syntax highli...

add foreign key support for RoR 3.0?

im using migration files to create the database tables but i want to set up foreign keys too. is there any good gem for this? i cant find gems for 3.0. thanks ...

undefined method `reflect_on_association' for Class:Class error when saving

UPDATE Got it to work by using has_and_belongs_to_many Anyone know why this works ? Hi, I get the following error when saving with active record undefined method `reflect_on_association' for Class:Class my relationships look like this : class Contact < ActiveRecord::Base has_many :classes has_many :sessions, :through => :cl...

How do i change column type in Heroku?

I am trying to rake the db:migrations into my heorku instance and I get an error. The FAQ described my error as below: Cannot change column type Example: PGError: ERROR: column “verified_at” cannot be cast to type “date” Cause: PostgreSQL doesn’t know how to cast all the rows in that table to the specified type. Mo...

how do i add fixture files in RoR3?

i wonder how i can add fixture data in RoR3? thanks ...

Suggestions for Ruby Gem authoring (ie. setup, environment etc)

I've been developing Rails apps now for about a year and am starting on a new project (that's actually 3 projects). I'd like to write some gems that can be shared amongst these projects to maintain a common code-base. They'll likely eventually evolve into Rails engines at some point, but to start, just common libraries that can be incl...

validation in RoR3

there are 2 ways to write validations in RoR3. validates_length_of :name, :minimum => 5 validates :name, :length => { :minimum => 5 } both will give the same. i wonder where i can read more about the latter one. all the options for it. cause the http://guides.rails.info/activerecord_validations_callbacks.html just mention th...

Test with shoulda macro fails with error

Hello! I have model: class Company < ActiveRecord::Base attr_accessible :name, :address, :description, :email, :www validates_presence_of :name, :address, :email validates_uniqueness_of :user, :name, :email validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create has_many :items, :...

Rails 3 jquery in js.erb template is creating escaped html?

In Rails 3, I've got an update.js.erb template with one simple line of jquery: $("#some_div").html("<strong>some_content</strong>"); Upon form submission, all the ajaxy stuff is working fine, but the content in #some_div is being replaced with "<strong>some_content</strong>" instead of some_content. Does anyone have a clue why? This ...

Using Rails to_xml(:methods =>) options need the method to be wrapped as cdata

I am using Rails 2.3.4 and "to_xml" with the :methods => option, and I want to include a Base64 encoded thumbnail image. Is there any way I can specify that that method needs to be wrapped in a cdata tag? Example: render :xml => @items.to_xml( :include => [:photos,:comments], :methods => [:encoded_thumb]) { |xml| xml.t...