I''ve implemented helpers and other support code for easily putting "ajaxed" choosers for the target of a belongs_to association into views. The code is on the wiki at http://wiki.rubyonrails.com/rails/show/AssociationHelper And as I haven''t got any comments there so far, I''d like to ask you in here for your comments and suggestions for improvement. Michael -- Michael Schuerig Airtight arguments have mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org vacuous conclusions. http://www.schuerig.de/michael/ --A.O. Rorty, Explaining Emotions
That sounds neat. Can we see it running anywhere? Steve On 5/11/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> > I''ve implemented helpers and other support code for easily putting > "ajaxed" choosers for the target of a belongs_to association into > views. The code is on the wiki at > > http://wiki.rubyonrails.com/rails/show/AssociationHelper > > And as I haven''t got any comments there so far, I''d like to ask you in > here for your comments and suggestions for improvement. > > Michael > > -- > Michael Schuerig Airtight arguments have > mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org vacuous conclusions. > http://www.schuerig.de/michael/ --A.O. Rorty, Explaining Emotions > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Wednesday 11 May 2005 22:46, Steve Willer wrote:> That sounds neat. Can we see it running anywhere?No, I''m sorry, I have no access to a public server running Rails. There isn''t much to see anyway. I''ll do my best to describe it picturesquely. Say, in your view code you''ve got the following <%= belongs_to_field(''project'', ''manager'', :size => 30) do |mgr| "#{mgr.lastname}, #{mgr.firstname}" if mgr; end %> When the view is rendered, this shows looks like an ordinary text field. In fact, it is one, albeit a read-only one. Originally, the field contains the lastname and firstname of the associated manager, if there is one. When the field receives the focus by clicking or tabbing, it is overlaid with an editable query text field containing the same text. Also, a server request with this text as query parameter is triggered. The found matches are displayed in a "popoup" select box. Then, any time the contents of the query field are changed, a new request is send to the server and its results are displayed in the popup. My intention is that in a majority of cases one gets this functionality with just one or two lines in the view, as shown above, and with equally few lines of code in the accessed controller. In this particular case, the stuff below is all that''s needed require_dependency ''ajax_support'' class EmployeeController < ApplicationController define_search_action :ajax, Employee, ''%lastname%, %firstname%'', :limit => 10, :select_size => 3 Michael -- Michael Schuerig The more it stays the same, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org The less it changes! http://www.schuerig.de/michael/ --Spinal Tap, The Majesty of Rock
In article <200505112215.00436.michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org>, michael- q5aiKMLteq4b1SvskN2V4Q-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> I''ve implemented helpers and other support code for easily putting > "ajaxed" choosers for the target of a belongs_to association into > views. The code is on the wiki at > > http://wiki.rubyonrails.com/rails/show/AssociationHelper > > And as I haven''t got any comments there so far, I''d like to ask you in > here for your comments and suggestions for improvement.That''s great! I need just such a thing. I am starting dev in the next few days; I will post comments. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
Michael Schuerig wrote:> I''ve implemented helpers and other support code for easily putting > "ajaxed" choosers for the target of a belongs_to association into > views. The code is on the wiki at > > http://wiki.rubyonrails.com/rails/show/AssociationHelperWonderful, I will eventually need this for associating existing images with products in my eCommerce application. Is it possible to use images and so on in the pop up? (I''ve not yet had a detailed look...) What I wonder about: What sort of fallback is there for non-javascript platforms? I''d like to remain compatible, just in case... Anyway, good work and I''d like to see something like this in Rails itself.
On Thursday 12 May 2005 01:04, Florian Groß wrote:> Michael Schuerig wrote: > > I''ve implemented helpers and other support code for easily putting > > "ajaxed" choosers for the target of a belongs_to association into > > views. The code is on the wiki at > > > > http://wiki.rubyonrails.com/rails/show/AssociationHelper > > Wonderful, I will eventually need this for associating existing > images with products in my eCommerce application. Is it possible to > use images and so on in the pop up? (I''ve not yet had a detailed > look...)The pop-up is just a div element whose innerHTML is filled by a field observer (-> prototype.js). Thus it displays anything the action method in your controller throws at it. Currently, though, the client-side JavaScript function wouldn''t be able to handle it. You''d have to extend _handleClick in a way so that it can translate a click in your content to (1) the text to be displayed and (2) the primary key of the associated object.> What I wonder about: What sort of fallback is there for > non-javascript platforms? I''d like to remain compatible, just in > case...Nothing yet. And I''m doubtful if this can be achieved within the bounds of these helper methods. It''s always theoretically possible to return a select element with all available options pre-filled. Now if that''s really workable, I''d recommend to do it in most cases over the AJAX approach. AJAXing becomes sensible precisely when there are too many options to shove them to the browser in their entirety. In such a case, it''s preferable to transfer only a subset matching certain query criteria. The same can surely be achieved without JavaScript/AJAX, and instead doing a page (re)load with changed options. View and controller would have to support this, whereas with the AJAX approach, the controller of the current view is oblivious to where the selectable objects come from.> Anyway, good work and I''d like to see something like this in Rails > itself.Not so quick. Have a close look at it first... Actually, there isn''t much code, with hindsight it''s all pretty straightforward. Michael -- Michael Schuerig The more it stays the same, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org The less it changes! http://www.schuerig.de/michael/ --Spinal Tap, The Majesty of Rock
On 5/11/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote:> I''ve implemented helpers and other support code for easily putting > "ajaxed" choosers for the target of a belongs_to association into > views. The code is on the wiki atHi, I was looking through your code, have you got any examples?
On Tuesday 17 May 2005 17:17, Giovanni Intini wrote:> On 5/11/05, Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> wrote: > > I''ve implemented helpers and other support code for easily putting > > "ajaxed" choosers for the target of a belongs_to association into > > views. The code is on the wiki at > > Hi, I was looking through your code, have you got any examples?Something like this is all you need in your view. <%= belongs_to_field(''project'', ''manager'') { |it| it.name if it } %> Michael -- Michael Schuerig There is no matrix, mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org only reality. http://www.schuerig.de/michael/ --Lawrence Fishburn