ruby-on-rails3

Ruby on Rails: compose attribute of model from virtual attributes

I have attribute name of model Person. I want to use html-form with fields: first_name and surname: <%= f.text_field first_name%> <%= f.text_field surname%> And I want to compose these virtual attributes to model attribute name. What's the best way to do it? I tried to use composed_of, but failed... class Person < ActiveRecord::Ba...

Rails 3.0.0 RC ActionController::RoutingError "No route matches"

Had a working app with Rails 3.0.0beta4 and just updated to the RC. Getting a new strange error. For some reason when I try to: <%= link_to "test", user %> The user is routed as resources :users yet it complains about no route for "action => destroy" despite I'm not even trying to link to destroy: ActionController::RoutingError...

ActiveRecord::Relation join, how to add a column of a join table to the query result with a new name?

To set the stage, I'm using rails 3 and I have these tables and relationships: user has_many lists list has_many tasks task has_many stints I would like to build a query that allows me to select all of the current users stints, and to have the list.id available as an attribute on each stint in the result. I would need to rename list.i...

HABTM Formtastic as check_boxes defaults all check_box options to selected on new action

I have a HABTM relationship on one of my models. I'm using formtastic for my forms. On a new action when choosing to output my column (HABTM) as check_boxes I see all my options appear, however they are all checked on by default. Ideally I want them to not be selected on a new action. When I uncheck a few options and save them, I will se...

Rails 3 has_one routing

I have two classes: class User < ActiveRecord::Base :has_one :foo end class Foo < ActiveRecord::Base :belongs_to :user end The Foo is optional. I created the following routing: resources :users do resources :foo end Which results in the following routes: GET /users/:user_id/foo(.:format) {:controller=>"foo...

How do I properly arrange my Gemfile for Rails 3?

I am trying to install vote-fu into my rails 3 project. The documentation ( for rails 2 ) says to install it into my environments.rb file as so.. config.gem "peteonrails-vote_fu", :lib => 'vote_fu', :source => 'http://gems.github.com' How could I convert that to rails 3 for the Gemfile? ...

Rails 3.0.0.rc profiling: Thousands of Regexp#===(d1) calls

I was getting 0.5 reqs/s on the front page of my rails app (a very simple, mostly static page that made a couple of database calls, but nothing that WEBrick said took longer than 0.8 ms), served with thin. I added ruby-prof profiling tools to my ApplicationController via the instructions at Dan Mange's blog and dumped the call graph to s...

jeditable and rails 3

Hello ! I'm trying to use jeditable with my rails 3 apps. I would like to edit some fields inline. Actually it's working on my client side but the data isn't updated in my app. Could you take a look? Thanks in advance! my view: <dt>Overview :</dt> <dd class="edit_textfield" id="<%= @project.id %>" name="overview"><%= @project.overview...

Solve rack issue for Dreamhost and Rails 3 rc

my environment.rb contains: ENV['GEM_PATH'] = File.expand_path('~/.gems') + ':/usr/lib/ruby/gems/1.8' My gemfile contains: source 'http://rubygems.org' source :gemcutter gem 'rails', '3.0.0.rc' gem 'mysql' gem 'haml' gem 'RedCloth' gem "friendly_id", "~> 3.0" gem 'agnostic-will_paginate', "~> 3.0.0" # Use unicorn as the web ser...

Best way to load module/class from lib folder in Rails 3?

Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore, what would be the best way to load them? From github: A few changes were done in this commit: Do not autoload code in *lib* for applications (now you need to explicitly require them). This makes an application behave closer to an engine (code...

activerecord to sequel transition

I'm using rails3.rc and activerecord3 (with meta_where) and just started to switch to sequel, because it seems to be muuuuch faster and offers some really great features :-) I'm already using the active_model plugin (and some others). But here are some questions I found and which I didn't find any documentation for: As far as I know, ...

Rails3 custom route format

In routes.rb I was forced to add: post 'admin/user_update' to get my form_tag to work: form_tag( { :action => :update_user, :id => @user.id }, :remote => :true ) Now I get: Template is missing Missing template admin/update_user with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in...

Reusing form_for in view for a mailer errors on forgery

I have a form_for in a template new.html.erb where I do the normal save to the DB and then an e-mail on success. I want the mailer to send the same new.html.erb as the body and pass the model so that the form is fully populated. I'm getting the following error: undefined method `protect_against_forgery?' for #<#<Class:0x000000049d7110>:...

Simulating has_and_belongs_to_many nested through behavior in Rails 3

So Rails doesn't have support for :through associations through a habtm relationship. There are plugins out there that will add this in for Rails 2.x, but I'm using Rails 3 / Edge, and only need the association for one particular model. So I thought I'd stump it out myself with the beauty that is Arel. First, the models: class CardSet ...

Render controller action from another controller

I think the code is more explicit option A class RedirectController < ApplicationController def index redirect_to :controller => 'posts', :action => 'show', :id => 1 # it works end end option B class RedirectController < ApplicationController def index render :controller => 'posts', :action => 'show', :id => 1 ...

'scoped' method for Rails 2.X ad Rails 3

Hi, I've got a plugin I'm using for websites using Rails 2.X or Rails 3. In Rails 2.3, I used a lot the 'scoped' method for complex queries : p = Person.scoped({}) p = p.active p = p.with_premium_plan if xyz p etc. But I saw that it changed in Rails 3 : p = Person.scoped etc. So is it normal that I have to do something like that ...

Install Facebooker on Rails 3RC With Ruby 1.9.2-RC2

I am trying to install the Facebooker plugin on Rails 3 RC with Ruby 1.9.2-RC2 but I am having some problems. when I run rails plugin install git://github.com/joren/facebooker.git I get the following error Plugin not found: ["git://github.com/joren/facebooker.git"] and the facebooker.yml configuration file is not being generate...

Rails 3: RJS vs JavaScript

Hi, I've recently started learning Ruby on Rails, based on RoR3 beta/RC. I had earlier been developing applications using other frameworks (like Django), where the JavaScript had been written completely on my own. When developing application using RoR, I get confused by the two possible ways of implementing JavaScript: the "pure" one (w...

'Bundle install' freezes when fetching source index

I'm trying to install MongoDB in Rails 3 but when I'm trying to run 'bundle install', it freezes in "Fetching source index...". I tried with rubygems.org and gemcutter.org and both of them freeze. Any ideas how to make it work? ...

Weird Rails 3 scope behavior

I've implemented the following scope in a rails 3 application: scope :popular, lambda { |l = 5| order('views desc').limit(l) } However, it seems that when you attempt to count its records directly it doesn't apply the scope filters. For example: Post.popular.size #=> 20 Checking the log, it executes the following query: SQL (0.4m...