Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Form helpers don't handle "question?" methods

#96

I'm carrying this forward from my Trac ticket (I rebased the changes to the current revision.)

The form helpers currently don't account for boolean question methods correctly (e.g. :secret?), so it outputs the question mark in the tag's name parameter. This patch fixes the name attribute so the returned parameter corresponds with the the right name for the model's setter method.

Currently, this code:

<%= f.check_box :secret? %>

Produces the following input tag:

<input name="post[secret?]" ... />

In fact, it should produce the following, so that the returned parameter can be directly assigned as :secret=, not :secret?=

<input name="post[secret]" ... />

This would be the expected behaviour for direct assignment back into the model using AR::Base.new, update_attributes, etc...

def create
  Post.new( params )

  # Currently have to work around the above mass assignment using:
  # secret = params.delete(:secret?)
  # Post.new( params )
  # Post.secret = secret
end

Reported by Andrew Vit · May 3rd, 2008 @ 06:49 PM

State: resolved
Milestone: none
Assigned to: Rick Rick
Importance: none

Activity

  1. Rick
    Rick
    • Assigned user set to Rick

    May 5th, 2008 @ 08:31 PM

  2. Andrew Vit
    Andrew Vit

    Updated patch to cache sanitized method name instead of doing the regex each time.

    May 5th, 2008 @ 08:50 PM

  3. Rick
    Rick
    • State changed from new to resolved

    Commmitted.. thanks.

    May 6th, 2008 @ 08:06 AM