[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Rails questions

Van Dyk, Joe

12/13/2004 7:43:00 PM

Spent some time this weekend working on a Rails application. It's great
stuff, coming from a php/mysql "hack it together" background. But I have a
couple questions...

1)
I have a controller called "houses". In that, there's an action called
"modify". modify's view (modify.rhtml) has a form with an action
"save_house". When the user hits submit, modify gets called with id
save_house (i.e. /houses/modify/save_house). What I want to have happen is
the action "save_house" called. I have another action "new", and new.rhtml
has a form with action "create_house", and when the user hits submit, the
action "create_house" is called, which is what I want to have happen. I'm
not sure why that's not the case with modify.

2)
has_and_belongs_to_many question: I have a model "House" that
has_and_belongs_to_many "Amenity". Is there a "Best Way(tm)" to display
this relationship in the controller/view? The way it works currently:

houses_controller#new:
@amenities=Amenities.find_all

new.rhtml:
(loops through @amenities, spits out checkboxes.)

house_controller#create:
@house = House.new(@params["house"].save
@house.amenities.clear
@params["amenities"].each do |amenity|
# @params["amenities"] is an array of amenity id's that the user
selected
temp_amenity = Amenities.new
temp_amenity.id = amenity
@house.amenities << amenity
end

This seems pretty clumsy to me.


Thanks for any input!

Joe


5 Answers

David Heinemeier Hansson

12/13/2004 9:59:00 PM

0

> 1)
> I have a controller called "houses". In that, there's an action called
> "modify". modify's view (modify.rhtml) has a form with an action
> "save_house". When the user hits submit, modify gets called with id
> save_house (i.e. /houses/modify/save_house). What I want to have
> happen is
> the action "save_house" called. I have another action "new", and
> new.rhtml
> has a form with action "create_house", and when the user hits submit,
> the
> action "create_house" is called, which is what I want to have happen.
> I'm
> not sure why that's not the case with modify.

It sounds like you're using scaffolding, which had a problem regarding
this in Rails 0.8.5. You can fix it manually by doing something like:

<%= form("house", :action => url_for(:action => "save_house")) %>

...if my guess at what your problem is have any grounding in reality.
This problem is fixed in the very forthcoming (and massive) Rails 0.9
upgrade.

> 2)
> has_and_belongs_to_many question: I have a model "House" that
> has_and_belongs_to_many "Amenity". Is there a "Best Way(tm)" to
> display
> this relationship in the controller/view? The way it works currently:
>
> house_controller#create:

@house = House.new(@params["house"].save
@house.amenities << Amenities.find(@params["amenities"])

Amenities.find accepts and array and will return a such.
@house.amenities.<< does the same and creates a link between the house
and amenity for each of the records found.

For followup questions, please consider signing up for the mailing
list[1] or get on IRC[2] for real-time help.

Thanks for enjoying Rails!

[1] http://lists.rubyonrails.org/mailman/list...
[2] http://www.rubyonrails.or...
--
David Heinemeier Hansson,
http://www.basec... -- Web-based Project Management
http://www.rubyon... -- Web-application framework for Ruby
http://macro... -- TextMate: Code and markup editor (OS X)
http://www.loudthi... -- Broadcasting Brain



alvin

4/15/2011 1:33:00 AM

0

On Apr 10, 9:33 pm, Andrew <agump...@gmail.com> wrote:
> On Apr 10, 6:14 pm, alvin <apbluth...@aol.com> wrote:
>
>
>
>
>
> > On Apr 10, 2:24 pm, Brad <b...@umich.edu> wrote:
>
> > > These are questions about "standard" American practice, i.e. what is
> > > in place if there have not been other discussed agreements in the
> > > partnership. I am interested to know how nearly "standard" this is:
>
> > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > signals count, instead of attitude or suit pref. Correct?
>
> > > 2. If leader then cashes the other high honor, setting up dummy's Q,
> > > 3rd hand's signal at this trick is suit pref. Correct?
>
> > > 3. If the bidding has already made it 100% clear to opening leader
> > > what partner's exact length in the suit is, and therefore an immediate
> > > count signal by 3rd hand would be useless, is 3rd hand's card
> > > attitude, suit pref, or still count?
>
> > > 4. Does any of this change if the partnership is playing "Ace for
> > > attitude, King for kount" against suits? Or, does the situation of
> > > guarded Q in dummy overrule everything?
>
> > > 5. Any other exceptional situations where 3rd hand's play behind the
> > > guarded Q should "automatically" mean such-and-such?
>
> > > Thanks,
> > > Brad Lehman
>
> > Brad:
>
> > here are my two cents on the your questions:
>
> > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > signals count, instead of attitude or suit pref. Correct?
>
> > I would think so. His attitude is known to be negative. Typically,
> > third hand will show a doubleton, if he is seeking a ruff. If he holds
> > three or more (so that no ruff is possible), go on to question 2.
>
> Alvin, you are implicitly saying that 3rd hand's signal is not a true
> count signal since you recommend false count from 4 to prevent opening
> leader from trying to give you a ruff.
>
> Andrew- Hide quoted text -
>
> - Show quoted text -

Andrew:

If, by count, you mean "parity," (i. e., oddness or evenness of the
holding), your reading of my intention is correct - I do not intend to
show this. In this situation being discussed (Qxx(x) in dummy; king
led from AK - same is true if the ace were led from this holding),
opener has no need to know whether his partner holds three or four (no
ruff being possible in either case), so I am not suggesting that these
numbers be clarified. This makes it clear, however, that a high spot
shows exactly two cards and the desire to take a ruff. Third hand
would also signal low (this is standard signalling, not UDCA) with a
doubleton and no desire for the ruff, e. g., holding a natural trump
trick where a ruff cannot add to the defensive trick count. This
signalling method allows opener to make a productive shift when third
hand does not seek the ruff.

Alvin P. Bluthman
apbluthman@aol.com

Andrew

4/15/2011 6:33:00 PM

0

On Apr 14, 6:33 pm, alvin <apbluth...@aol.com> wrote:
> On Apr 10, 9:33 pm, Andrew <agump...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > On Apr 10, 6:14 pm, alvin <apbluth...@aol.com> wrote:
>
> > > On Apr 10, 2:24 pm, Brad <b...@umich.edu> wrote:
>
> > > > These are questions about "standard" American practice, i.e. what is
> > > > in place if there have not been other discussed agreements in the
> > > > partnership. I am interested to know how nearly "standard" this is:
>
> > > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > > signals count, instead of attitude or suit pref. Correct?
>
> > > > 2. If leader then cashes the other high honor, setting up dummy's Q,
> > > > 3rd hand's signal at this trick is suit pref. Correct?
>
> > > > 3. If the bidding has already made it 100% clear to opening leader
> > > > what partner's exact length in the suit is, and therefore an immediate
> > > > count signal by 3rd hand would be useless, is 3rd hand's card
> > > > attitude, suit pref, or still count?
>
> > > > 4. Does any of this change if the partnership is playing "Ace for
> > > > attitude, King for kount" against suits? Or, does the situation of
> > > > guarded Q in dummy overrule everything?
>
> > > > 5. Any other exceptional situations where 3rd hand's play behind the
> > > > guarded Q should "automatically" mean such-and-such?
>
> > > > Thanks,
> > > > Brad Lehman
>
> > > Brad:
>
> > > here are my two cents on the your questions:
>
> > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > signals count, instead of attitude or suit pref. Correct?
>
> > > I would think so. His attitude is known to be negative. Typically,
> > > third hand will show a doubleton, if he is seeking a ruff. If he holds
> > > three or more (so that no ruff is possible), go on to question 2.
>
> > Alvin, you are implicitly saying that 3rd hand's signal is not a true
> > count signal since you recommend false count from 4 to prevent opening
> > leader from trying to give you a ruff.
>
> > Andrew- Hide quoted text -
>
> > - Show quoted text -
>
> Andrew:
>
> If, by count, you mean "parity," (i. e., oddness or evenness of the
> holding), your reading of my intention is correct - I do not intend to
> show this. In this situation being discussed (Qxx(x) in dummy; king
> led from AK - same is true if the ace were led from this holding),
> opener has no need to know whether his partner holds three or four (no
> ruff being possible in either case), so I am not suggesting that these
> numbers be clarified. This makes it clear, however, that a high spot
> shows exactly two cards and the desire to take a ruff. Third hand
> would also signal low (this is standard signalling, not UDCA) with a
> doubleton and no desire for the ruff, e. g., holding a natural trump
> trick where a ruff cannot add to the defensive trick count. This
> signalling method allows opener to make a productive shift when third
> hand does not seek the ruff.

You have described what I would call an attitude signal. Given that
signaller is known to hold none of the top 3 honors, he only signals
positive attitude to indicate desire to take a ruff.

IMO, a count signal is always a parity signal, pure and simple.


Andrew

alvin

4/19/2011 2:27:00 PM

0

On Apr 15, 2:32 pm, Andrew <agump...@gmail.com> wrote:
> On Apr 14, 6:33 pm, alvin <apbluth...@aol.com> wrote:
>
>
>
>
>
> > On Apr 10, 9:33 pm, Andrew <agump...@gmail.com> wrote:
>
> > > On Apr 10, 6:14 pm, alvin <apbluth...@aol.com> wrote:
>
> > > > On Apr 10, 2:24 pm, Brad <b...@umich.edu> wrote:
>
> > > > > These are questions about "standard" American practice, i.e. what is
> > > > > in place if there have not been other discussed agreements in the
> > > > > partnership. I am interested to know how nearly "standard" this is:
>
> > > > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > > > signals count, instead of attitude or suit pref. Correct?
>
> > > > > 2. If leader then cashes the other high honor, setting up dummy's Q,
> > > > > 3rd hand's signal at this trick is suit pref. Correct?
>
> > > > > 3. If the bidding has already made it 100% clear to opening leader
> > > > > what partner's exact length in the suit is, and therefore an immediate
> > > > > count signal by 3rd hand would be useless, is 3rd hand's card
> > > > > attitude, suit pref, or still count?
>
> > > > > 4. Does any of this change if the partnership is playing "Ace for
> > > > > attitude, King for kount" against suits? Or, does the situation of
> > > > > guarded Q in dummy overrule everything?
>
> > > > > 5. Any other exceptional situations where 3rd hand's play behind the
> > > > > guarded Q should "automatically" mean such-and-such?
>
> > > > > Thanks,
> > > > > Brad Lehman
>
> > > > Brad:
>
> > > > here are my two cents on the your questions:
>
> > > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > > signals count, instead of attitude or suit pref. Correct?
>
> > > > I would think so. His attitude is known to be negative. Typically,
> > > > third hand will show a doubleton, if he is seeking a ruff. If he holds
> > > > three or more (so that no ruff is possible), go on to question 2.
>
> > > Alvin, you are implicitly saying that 3rd hand's signal is not a true
> > > count signal since you recommend false count from 4 to prevent opening
> > > leader from trying to give you a ruff.
>
> > > Andrew- Hide quoted text -
>
> > > - Show quoted text -
>
> > Andrew:
>
> > If, by count, you mean "parity," (i. e., oddness or evenness of the
> > holding), your reading of my intention is correct - I do not intend to
> > show this. In this situation being discussed (Qxx(x) in dummy; king
> > led from AK - same is true if the ace were led from this holding),
> > opener has no need to know whether his partner holds three or four (no
> > ruff being possible in either case), so I am not suggesting that these
> > numbers be clarified. This makes it clear, however, that a high spot
> > shows exactly two cards and the desire to take a ruff. Third hand
> > would also signal low (this is standard signalling, not UDCA) with a
> > doubleton and no desire for the ruff, e. g., holding a natural trump
> > trick where a ruff cannot add to the defensive trick count. This
> > signalling method allows opener to make a productive shift when third
> > hand does not seek the ruff.
>
> You have described what I would call an attitude signal. Given that
> signaller is known to hold none of the top 3 honors, he only signals
> positive attitude to indicate desire to take a ruff.
>
> IMO, a count signal is always a parity signal, pure and simple.
>
> Andrew- Hide quoted text -
>
> - Show quoted text -

Andrew:

You present an interesting point: does showing a doubleton and seeking
aruff qualify as a count signal or as an attitude signal, when not
seeking to show other holdings with an even number of cards?

The Granovetters, for example, in A Switch in Time, p. 10, treat this
signal as a count signal WHEN SEEKING A RUFF. Although they state that
they do not give count with a tripleton (presumably they intend that
their low card in that situation is attitude), they do not directly
address a holding of four or six.

Kantar, in his "Big Red Book," Defensive Bridge Play Complete, treats
"the HIGH-LOW with a doubleton," as a case all of its own (see pp.
58-60) and suggests that you not signal this way, hollding the Qx, J
NOT visible in dummy (because the queen would promise the jack, not a
doublteon, in that situation). :



We can, of course, throw authorities at each other all we want, and
besides, as Lincoln pointed our, calling a dog's tail a leg doesn't
make it one.

alvin

4/19/2011 2:31:00 PM

0

On Apr 15, 2:32 pm, Andrew <agump...@gmail.com> wrote:
> On Apr 14, 6:33 pm, alvin <apbluth...@aol.com> wrote:
>
>
>
>
>
> > On Apr 10, 9:33 pm, Andrew <agump...@gmail.com> wrote:
>
> > > On Apr 10, 6:14 pm, alvin <apbluth...@aol.com> wrote:
>
> > > > On Apr 10, 2:24 pm, Brad <b...@umich.edu> wrote:
>
> > > > > These are questions about "standard" American practice, i.e. what is
> > > > > in place if there have not been other discussed agreements in the
> > > > > partnership. I am interested to know how nearly "standard" this is:
>
> > > > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > > > signals count, instead of attitude or suit pref. Correct?
>
> > > > > 2. If leader then cashes the other high honor, setting up dummy's Q,
> > > > > 3rd hand's signal at this trick is suit pref. Correct?
>
> > > > > 3. If the bidding has already made it 100% clear to opening leader
> > > > > what partner's exact length in the suit is, and therefore an immediate
> > > > > count signal by 3rd hand would be useless, is 3rd hand's card
> > > > > attitude, suit pref, or still count?
>
> > > > > 4. Does any of this change if the partnership is playing "Ace for
> > > > > attitude, King for kount" against suits? Or, does the situation of
> > > > > guarded Q in dummy overrule everything?
>
> > > > > 5. Any other exceptional situations where 3rd hand's play behind the
> > > > > guarded Q should "automatically" mean such-and-such?
>
> > > > > Thanks,
> > > > > Brad Lehman
>
> > > > Brad:
>
> > > > here are my two cents on the your questions:
>
> > > > 1. Partner leads A or K (from AK+) in a plain suit against a trump
> > > > contract, and dummy comes down with Qxx(x). 3rd hand now by default
> > > > signals count, instead of attitude or suit pref. Correct?
>
> > > > I would think so. His attitude is known to be negative. Typically,
> > > > third hand will show a doubleton, if he is seeking a ruff. If he holds
> > > > three or more (so that no ruff is possible), go on to question 2.
>
> > > Alvin, you are implicitly saying that 3rd hand's signal is not a true
> > > count signal since you recommend false count from 4 to prevent opening
> > > leader from trying to give you a ruff.
>
> > > Andrew- Hide quoted text -
>
> > > - Show quoted text -
>
> > Andrew:
>
> > If, by count, you mean "parity," (i. e., oddness or evenness of the
> > holding), your reading of my intention is correct - I do not intend to
> > show this. In this situation being discussed (Qxx(x) in dummy; king
> > led from AK - same is true if the ace were led from this holding),
> > opener has no need to know whether his partner holds three or four (no
> > ruff being possible in either case), so I am not suggesting that these
> > numbers be clarified. This makes it clear, however, that a high spot
> > shows exactly two cards and the desire to take a ruff. Third hand
> > would also signal low (this is standard signalling, not UDCA) with a
> > doubleton and no desire for the ruff, e. g., holding a natural trump
> > trick where a ruff cannot add to the defensive trick count. This
> > signalling method allows opener to make a productive shift when third
> > hand does not seek the ruff.
>
> You have described what I would call an attitude signal. Given that
> signaller is known to hold none of the top 3 honors, he only signals
> positive attitude to indicate desire to take a ruff.
>
> IMO, a count signal is always a parity signal, pure and simple.
>
> Andrew- Hide quoted text -
>
> - Show quoted text -

Andrew:

Sorry, I sent you my latest posting before finishing it. I was adding
that neither the Granovetters nor Kantar seem to fully address the
point you are making. And if you require that a count signal
consistently show all possible odd numbers or all possible even
numbers then, as you state, this signal is an attitude signal, simply
becasuse I do not do that. Still, whatever you call it, it works
better than showing either two or four withour distinguishing between
them. And iot also works better than indescriminately showing a
doubleton, whether olr not you are seeking a ruff or whether you play
a card (such as the queen, from Qx) that can be misunderstood. So, I
fully udnerstand your statement that thbisis showing attidue (please
continue, rather than please shift). I simply think this is the right
way to signal in this situation.

Alvin