Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6760015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:01:07+00:00 2026-05-26T14:01:07+00:00

So perhaps I’ve found a bug in Rails 3.1.1, or else I don’t understand

  • 0

So perhaps I’ve found a bug in Rails 3.1.1, or else I don’t understand if Rails 3.1(.1) has changed in some way from Rails 3.0.10 with Nested Resources, Polymorphic associations, and/or routing…

Under Rails 3.0.10 the following works fine, but under Rails 3.1.1 it doesn’t!

These are my models:

class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
end

class Employee < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

class Product < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

My routes.rb:

resources :employees do
  resources :pictures
end
resources :products do
  resources :pictures
end

My controller:

class PicturesController < ApplicationController
  def index
    @imageable = find_imageable
    @pictures = @imageable.pictures
  end

  private
  def find_imageable
    params.each do |name, value|
      if name =~ /(.+)_id$/
        return $1.classify.constantize.find(value)
      end
    end
    nil
  end
end

My app/views/pictures/index.html.erb:

<% form_for [@imageable, Picture.new] do |f| %>
    <p><%= f.submit "Add picture" %></p>
<% end %>

I generated the apps with rails new poly -T (for Rails 3.1.1 and for Rails 3.0.10).

I used standard scaffold commands: rails g scaffold Employee name:string, rails g scaffold Product title:string and rails g scaffold Picture caption:string imageable_id:integer imageable_type:string and then migrating, of course.

When hitting the index form (/employees first to create an employee with id == 1; then /employees/1/pictures) I get a blank form (no button appears) on Rails 3.1.1, and a form with the submit button on it, on Rails 3.0.10…

Any ideas if I’m doing something wrong in Rails 3.1.1, or have I really found a bug (I doubt it–I’m sure I’m doing something stupid!)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:01:07+00:00Added an answer on May 26, 2026 at 2:01 pm

    In the line:

    <% form_for [@imageable, Picture.new] do |f| %>
    

    You are missing the = after the <%. The line should be

    #notice the = symbol:
    <%= form_for [@imageable, Picture.new] do |f| %>
    

    The older style <% syntax for form_for, field_for etc., was deprecated and scheduled for removal in 3.1, if I remember correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps I don't understand events fully. I'm building a Windows Phone 7 app in
Perhaps I don't understand how clone() works. Shouldn't the return value equal the caller?
Perhaps the most obvious way of protecting a company's intellectual property from its own
Perhaps there is a better way to do this, but here's where I'm at
Perhaps I am missing something simple. I added a modal segue from a button
Perhaps there's a better way to set this up so I'm open to suggestions.
Perhaps I haven't found the right post but I have been unable to set
Perhaps this is mere wishful thinking, but is there a simple way (in ASP.NET)
Perhaps this is a duplicate question, but I havn't found something by myself. Basically
Perhaps I'm using the OpenFileDialog incorrectly, but I've found that unhandled exceptions are being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.