SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    wrong argument type String (expected Module)

    hi,

    I don't understand this error. I have an STI table "properties" with different children like House, Flat, Land...
    when I want to add a new property, instead of creating a new House or Flat, I do New Property and list in a select box the different types but I get this error

    It works for any column in the table except the type column. Should I create directly the proper subclass (ie new Home instead of new Property)?

    PHP Code:
    <p><label for="property_type">Type</label><br/>
    <%= 
    options = [["Select Type"""]] + Property::TYPES
        select
    ('property''type'options) %></p
    where Property::TYPES is an array like that:
    TYPES = [
    ["House", "House"],
    ["Flat", "Flat"],
    ["Plot", "Plot"]
    ]

  2. #2
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a feeling that "type" is a reserved column name, though I'm not sure where the documentation for it is.
    Hello World

  3. #3
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Yeah, try PROPERTY_TYPES

    I'm guessing you're basing this on the code for the Depot app in the Agile book? It's Order::PAYMENT_TYPES in there. Even in that sample, they recommend putting the types in their own database table if there's a chance of new types being added/changed/removed.

  4. #4
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm guessing you're basing this on the code for the Depot app in the Agile book?

    Yes , I thought it was a reserved word so I tried PROPERTY_TYPES but I had the same message.

    I should probably move it to a new table but I'll have to do another join. I have already 2 foreign keys, I thought it was enough

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have no idea how kosher this code is, but I hard coded a small list of options into a view using:

    Code:
    <select id="answernew_correct" name="answernew[correct]">
            <%= options_for_select [["Wrong","0"],["Correct","1"]]  %>
    </select>
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  6. #6
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by sweatje
    I have no idea how kosher this code is, but I hard coded a small list of options into a view using:

    Code:
    <select id="answernew_correct" name="answernew[correct]">
            <%= options_for_select [["Wrong","0"],["Correct","1"]]  %>
    </select>
    That's fine as long as you don't repeat yourself with that array anywhere else

  7. #7
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Still stuck with this STI stuff...

    I uses a good old html select to avoid the error
    PHP Code:
    <td><label for="property_type">Type</label>:</td>
        <
    td><select id="property_type" name="property[type]">
        <
    option value="Home">Home</option>
        <
    option value="Flat">Flat</option
    the rendered rhtml is ok but it doesn't create/update the type column

    The same code for another field does the job so there is really something wrong with STI but I don't understand what. Any idea?

  8. #8
    SitePoint Zealot HenriIV's Avatar
    Join Date
    Jun 2004
    Location
    France
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've found an interesting tip to fix this type thing on the RoR forum:
    http://www.ruby-forum.com/topic/67826#new

    Posted by Trevor Squires (Guest)
    on 02.06.2006 01:30

    On 1-Jun-06, at 2:26 PM, Josh Susser wrote:

    >
    > def inheritance_column
    > "something_other_than_type"
    > end
    >

    Sorry but that's not the way to go. The inheritance_column method is
    a *class* method.

    Regardless, I believe the correct call is set_inheritance_column. I.e.:

    class MyModel < ActiveRecord::Base
    set_inheritance_column :ruby_type
    end

    However, if you want to access the value for the 'type' field in your
    table you can't do:

    model.type

    you have to use:

    model[:type]

    All in all, if you can avoid it then don't have a column called
    "type". I don't even use it for STI - a while back I picked up a
    habit of always setting the inheritance column to be 'ruby_type'.

    That way I can do model.type() to get back the class object and
    model.ruby_type (and model.ruby_type=) to access the string
    representation of the class name.
    I think I'm going to adopt ruby_type


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •