ruby-on-rails3

Ruby on Rails 3 howto make 'OR' condition

I need an SQL statement that check if one condition is satisfied: SELECT * FROM my_table WHERE my_table.x=1 OR my_table.y=1 I want to do this the 'Rails 3' way. I was looking for something like: Account.where(:id => 1).or.where(:id => 2) I know that I can always fallback to sql or a conditions string. However, in my experience this...

Getting async http requests to work on rails 3beta4/ruby 1.9.2-rc2/thin/eventmachine

I've been trying to get basic async HTTP calls to work in my app. I've tried using some code in my app from the Rails 3 async stack demo: http://github.com/igrigorik/async-rails, but I'm getting "can't yield from root fiber" and I have no idea where to go from here. Here's the top of my trace: (eval):10:in `yield' (eval):10:in `get' a...

Regex Pop Quiz Question of the Day

Suppose I want to turn this : http://en.wikipedia.org/wiki/Anarchy into this : en.wikipedia.org or even better, this : wikipedia.org Is this even possible in regex? ...

Rails 3: @template variable inside controllers is nil

Hi all, i've started using rails 3 beta3 and I have see that the @template variable inside controllers is nil. How I can call helpers methods inside a controller? Thx ...

declarative_authorization: control access to nested resource that doesn't have an explicit model

I have a model that allows a User to mark other Users as Favorites. This HABTM relationship is defined in the User model: class User < ActiveRecord::Base has_and_belongs_to_many :favorites, :class_name => "User", :join_table => "favorites", :association_foreign_key => "favorite_id", :foreign_key => "user_id" end The FavoritesControl...

Same model being loaded twice though controller specifies 2 different models

Rails 3... I have a controller.. class OrdersController < ApplicationController def index @os_orders = OrlandoOrder.all @ct_orders = ChicagoOrder.all end end And then I have the two models defined... class ChicagoOrder < Order Order::ActiveRecord::Base.table_name_prefix = 'ct_schema.' end class OrlandoOrder < Order ...

rvm conflit with sqlite3

Hi $: /Users/dev/.rvm/gems/ruby-1.9.2-head@rails3/gems/sqlite3-ruby-1.3.1/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] Abort trap It's seem that ruby is not the correct version (1.8.7) but : $: ruby - v $: ruby 1.9.2dev (2010-07-15 revision 28653) [x86_64-d...

Mounting multiple instances of the same engine in Rails 3

Hi, I'm wanting to make use of the new modularity prospects offered by the architecture changes in rails 3. However, rather than just mount an engine as in the majority of examples... Rails.application.routes.draw do match "/blog" => Rack::Blog end ...I'd like to mount multiple versions of the same engines, and have those instance...

Mongomapper/mongoDB: SystemStackError: stack level too deep

I have a Rails 3 model "D" that belongs to another model, which belongs to another two in turn, like this: D belongs to C C belongs to B B belongs to A I am using MongoDB/Mongomapper as my ORM. When I try to instantiate D, I am getting an error: ruby-1.9.2-preview3 > d = D.new SystemStackError: stack level too deep from /Users/peter...

Question about ActiveRecord#default_scope method and default ordering

Question about default_scope with Rails 2/3. On my Rails 3 project, I'm using a lot default_scope to order by created_at desc. So first I wrote : default_scope order("created_at desc") in many of my models. But the problem is that created_at exist in almost every of my application tables... So if I write a query that simply makes a j...

Missing templates from new Rails 3 app?

Just tried writing a simple validates_presence_of in my model, and when the errors try to render, it calls this : Template is missing Missing template posts/create with {:locale=>[:en, :en], :handlers=>[:builder, :rjs, :erb, :rhtml, :rxml, :haml], :formats=>[:html]} in view paths "/Users/johnsmith/Sites/shwagr/app/views" Errors don't...

Rails inherited resources usage

Hi, I'm using Inherited Resources for my Rails 2.3 web service app. It's a great library which is part of Rails 3. I'm trying to figure out the best practice for outputting the result. class Api::ItemsController < InheritedResources::Base respond_to :xml, :json def create @error = nil @error = not_authorized if !@use...

Rails3 setting focus on a textfield

When I have errors in a form, I would like to set the focus to the first textfield with the error. I've done this with PHP and JavaScript in the past, but I'm not sure how to approach it in rails3. Thanks in advance ...

Ym4r can't convert to string for rails3

Here's some background of my problem: I am on Snow Leopard I have RVM installed(using a ruby1.9.2-head installation) I am using rails3 I installed the ym4r using this http://github.com/guilleiguaran/ym4r_gm (and followed the tutorial) Anyway, I added these to my controller: @map = GMap.new("map_div") @map.control_init(:large_map => tr...

Rails3 get current layout name inside view

I have the answer for the Rails 2.X but not for Rails 3. How can I read the name of a current layout rendered inside a view. My Rails2 question: http://stackoverflow.com/questions/2622219/rails-layout-name-inside-view Thx. ...

Ruby on Rails 3 Release date

Hi, Is there a release date for Ruby on Rails 3? I've been searching but nothing yet. ...

number of guests in ruby on rails

Is there an easy way to count the number of active users or guests (not logged in users) visiting my rails app? Right now I have a way to count the number of logged in users in the last 15 minutes by having a last_seen_at column for the user. However I don't want to use the database to figure out the total number of active users or gue...

How to make Ajax calls with Rails 3 using remote_function?

I am trying to make an onchange call on a select box.For my application i am using jquery.js and rails.js as mentioned to make use of UJS. But still the code that is generated is for Prototype and not for jquery ajax calls. My code looks like the following: <%=select_tag :category,options_for_select(Category.find(:all,:select=>"name,id"...

How to avoid deprecation warning with named_scope (rails 2.X) / scope (rails 3) class_method

Hi, I build several plugins using the class method 'named_scope', which has been deprecated and replaced by 'scope' in Rails 3. I would like to avoid the following warning as I have lot a scopes present in my plugins : DEPRECATION WARNING: Base.named_scope has been deprecated, please use Base.scope instead. How to you deal with that?...

How to view a rails email from a url

As one tiny part of making authoring html emails less painful, I'd like to be able to view what I'm making without sending it to myself. This will also help later, with an "Email not displaying correctly? View it in your browser!" link. I'm working with Rails 3 (thus far ActionMailer 3.0 is a delight) and have an email model called "Not...