Condition on fields_for

Do these addresses have any difference besides being primary or secondary? Are there extra fields in one that are not in the other? Or is primary maybe a boolean on the address object?

Walter

Create two associations with conditions on the parent table with conditions that point to each “type” of address.

For instance:

has_many :addresses

has_one :primary_address,

->() do

where( :type => :primary )

end,

:class_name => Address

This will make primary address accessible through addresses but also make it its own association ( so you can just pass that association to the form ).

Be aware that changes to one association will not be reflected in the other. So if you change “primary_address”, before you reload, the object in addresses which corresponds to your primary address will not have the changes you made to primary address. After you save/reload, they will.

*changes to one association will not be reflected in the other until reload.

Is @lenders a single parent or an array? Presumable an array since it
is plural. In which case you can't just test state_id_string.
Possibly you need something like @lenders.where(some condition on
state_id_string), assuming that state_id_string is a database field.
Alternatively perhaps you want to use @lenders.each to select and test
them one at a time.

Colin

Okay... I am really trying to be super vigilant to best Ruby/Ruby on Rails
practices here... the whole n + 1 matter particularly

I have a parent table called Advertiser:

This is how it looks on the database:

CREATE TABLE advertisers (
  advertiser_id varchar(40) NOT NULL,

If you are committed to the rails conventions then that should just be
id, not advertiser_id. advertiser_id should be used in another table
that belongs_to advertiser.

  title varchar(50) NOT NULL,
  category_id int(3) NOT NULL DEFAULT '99',
...
class Advertiser < ActiveRecord::Base

  require 'uri'

  self.primary_key = 'advertiser_id'
  attr_accessor :item_image_upload
  has_one :item_image
  has_one :category

You have has_one category, but also a category_id in the table either
it should be belongs_to category or the field should not be there.

...
CREATE TABLE categories (
  category_id int(3) NOT NULL DEFAULT '99',
  category_type varchar(50) NOT NULL,
  KEY category_type_index (category_type)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Categories exists as category.rb, and this is the model:

class Category < ActiveRecord::Base

self.primary_key = 'category_id'

  belongs_to :advertiser
  belongs_to :borrower
  belongs_to :lender

You need _id fields for each of the above.

...
    I am really committed to using best practices. What an I doing wrong?
I am not clear as to model requirement regarding look up values that are
user nonchangeable... The whole notion, for example, has_one with regard to
a look up is not clear to me.

Have you worked right through a good tutorial such as
railstutorial.org (which is free to use online), including all the
exercises? That should help to make the basics of rails more clear.

Colin

Who are you saying thank you to? The quoted message did not seem to
include any help. It might be better to put your reply after the
relevant section of the message you are replying to (as I have done
here), then it is easier to follow what you are saying.

Colin

I am thanking you, Colin

That is ok, glad to be of help. However I note you ignored my other
suggestion, or at least did not act on it. I was:

It might be better to put your reply after the
relevant section of the message you are replying to (as I have done
here), then it is easier to follow what you are saying.

Cheers

Colin

Nobody has suggested that you have not thanked folks. What I was
commenting on was the fact that you have been replying at the top of
the previous message rather than replying to it with comments inserted
in the previous message at appropriate points, which I think is more
appropriate for technical mailing lists and is generally the
convention on this list. I see that you are using gmail, perhaps you
do not know that gmail hides the previous message by default, but if
you click on the three little dots that appear at the bottom of the
text window when you click Reply then it will show the previous
message so you can insert your reply at the appropriate point.

Cheers

Colin

This is an old post, but I hope I can help with the seeming confusion : )
Liz, what Colin was referring to is this
http://en.wikipedia.org/wiki/Posting_style.
Colin prefers inline-or-bottom-posting-with-trimmed-quotes over
top-posting-with-full-quotes (wc you prefer). In a way, Colin is
telling you to help him help you better.

hope that helps.
kind regards --botp