ruby-on-rails

Rails friendly url routing with open id

I would like to use create a rails route for a user's open id. The url would look something like http://mysite.com/identity/:html_encoded_openid or http://mysite.com/identity/:html_encoded_openid.xml This would be so that the site could be queried for an open id and either view info for that identity or receive an xml document contai...

Adding a photo to a model's has_many model from a view

I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to manage everything. On the "show" view for Thing, I want to have a file upload, and have it relate to the Thing model. For some reason, I'm totally glitching on how this should be done. I've tried doing this (Haml): - form_for @thing.thing_photos, :html => {:...

Why is ActiveRecord issuing a separate query per join?

I'm doing an ActiveRecord find operation (via the "will_paginate" library) like this: contacts = Contact.paginate(:all, :conditions => conditions_specified, :select => "DISTINCT contacts.*", :joins => joins, :include => [:addresses, :emails, :phone_numbers, {:addresses => :organization}], :page => page, :per_pa...

I can read but not set cookies in my rails app.

It's the weirdest thing. When I ran the Rails WEBrick debugger yesterday I could do things like cookies[uid] = s.session_id where 'uid' is a passed argument that has a user id in it, and then expect cookies[uid] to give me back, say: 29b93443d9ec18168a26e1ab12957b0dd0b799ff Today, I always get back 'nil'. I can read existing va...

What (if any) technical debt am I incurring with Ruby on Rails?

I'm a big fan of ruby on rails, and it seems to incorporate many of the 'greatest hits' of web application programming techniques. Convention over configuration in particular is a big win to my mind. However I also have the feeling that some of the convenience I am getting is coming at the expense of technical debt that will need to be ...

Using named_scope to get row count

Rails gurus: I've just discovered named_scope thanks to another SO user. :) I'd like to get the count of a set of rows - i.e. a SELECT COUNT(*). Additionally, I want to still be able to chain named scopes in the call. Is this a legitimate (albeit weird) usage of named scope? named_scope :count, :select => "COUNT(*) as count_all" So...

RubyOnRails 2.2 + Jquery UI Sortable & AJAX: This is how I did it. Is there a better way?

Hello, In a Rails 2.2 project, I'm having users put together a list of projects into a portfolio object (i.e.: PortfolioHasManyProjects). On the page is a Rails form for regular text, titles etc., as well as 2 sortable lists; the lists are used for dragging projects from the global-project-list into your portfolio-project-list. It is s...

How to keep track of the most popular products

I'm trying to implement a "Popular Products" feature. Basically, every time a Product is viewed, I want to log to the database the number of views of that product. Where do I put the hooks for something like this? I have seen things that are based on building some sort of traffic analytics, but I am looking for ideas that would keep this...

Master detail example of Rails

Can anyone point me to a master detail implementation in Rails? I Googled but couldn't find any good example sites. ...

Cleanest way to create a Hash from an Array

I seem to run into this very often. I need to build a Hash from an array using an attribute of each object in the array as the key. Lets say I need a hash of example uses ActiveRecord objecs keyed by their ids Common way: ary = [collection of ActiveRecord objects] hash = ary.inject({}) {|hash, obj| hash[obj.id] = obj } Another Way: ...

When I run the rake:db migrate command I get an error "Uninitialized constant CreateArticles"

Hi, I created a model ruby script/generate model Article (simple enuff) Here is the migration file create_articles.rb: def self.up create_table :articles do |t| t.column :user_id, :integer t.column :title, :string t.column :synopsis, :text, :limit => 1000 t.column :body, :text, :limit => 20000 t.column :published...

database configuration does not specify adapter

Hi all, I'm getting this error when I'm trying to connect to a mysql database. The problem is that the application works for weeks, and then randomly I get this message. When I get this error message the application is not able to reconnect to the database until I restart it. I'm using a configuration file to connect to the database, a...

Integrating Oulook/Exchange Tasks with Linux-based Rails

Is it possible to integrate MS Outlook/Exchange tasks with Rails? I know how to send emails with Rails, but that isn't using anything "special" about exchange, just pointing it at the server. What is "special" about an Outlook Task and how I can I create/read/update/delete them from Rails. (Even a subset of CRUD would be great.) PS. I ...

Rails: Creating an HTML Snippet with a Variable?

I have a submit button that is a block of HTML code because of styling and images to make it look better. (I stole most of it from Wufoo). This is one every form in the application and I was wondering if there is a cleaner way to do this. Something like a partial or helper? The name of the button "Submit" or "Add Contact" needs to be ...

Is there a CRUD generator utility in Java(any framework) like Scaffolding in Rails?

Is there a CRUD generator utility in Java like Scaffolding in Rails? Can be in any framework or even plain servlets. Must generate controllers + views in jsp, not just DAO code... ...

Rails controller does not accept JSON?

Hi All, I am trying to create an ActiveRecord object via a JSON request. However the controller fails to set the variables passed in the parameters in the newly created object. As an example, a person object has two fields: firstname and lastname. The JSON generated by the JSON.stringify function of the JSON.org library produces: {"fi...

Rails: For each Array giving Error?

In one form I am creating a territory and editing multiple users. The "user_attributes" below are for the users and the "name" is for the territory. So for each user_attribute I wanted to update the user model. params { "territory"=>{"name"=>"Central Canada", "user_attributes"=>[{"user_id"=>"30"},{"user_id"=>"30"}]} } create action...

Why am I suddenly getting Missing Template errors with edge Rails (2.3)?

After freezing edge rails, all my controller examples are failing with MissingTemplate errors. e.g., "Missing template attachments/create.erb in view path app/views" Trying to actually render the views gives me the same error. I noticed I can fix most of them by using respond_to but I usually never use it. I almost always only need to ...

Rails Plugins

What are some of your favorite rails plugins that you would consider "must haves"? This entry lists some of my favorites that I use in a large majority of my rails applications: My favorite rails plugins ...

Add Rows on Migrations

Hi! I'd like to know which is the preferred way to add records to a database table in a Rails Migration. I've read on Ola Bini's book (Jruby on Rails) that he does something like this: class CreateProductCategories < ActiveRecord::Migration #defines the AR class class ProductType < ActiveRecord::Base; end def self.up #CREAT...