El Wednesday 28 January 2009 22:31:48 chris escribió:
> I've been searching all day for a way to make this work and I've found
> bits and piece but I can't seem to put it all together. How do I
> filter a table dynamically using a drop down box?
>
> I've seen references to conditions_for_collection and maybe that's the
> direction I need to go any help would be greatly appreciated.
>
> --- index.html.erb ----
>
> Drop Down:
>
> <%= select("promotion", "promotion_type_id", PromotionType.find
> (:all).collect {|p| [p.promotype, p.id]}) %>
>
> Active Scaffold
>
> <%= render :active_scaffold => 'promotion_spots', :constraints =>
> {:account_id => @account.id}, :conditions => "promotion_type_id=#
> {'promotion_promotion_type_id}" %>
>
> I'm not sure how to link the drop down box to active_scaffold and have
> the table reload the content dynamically.
>
The select must be in a form and you must send the form when you change the
selected value, using a submit button or sending by ajax.
In the controller you get the value in params hash:
@promotion_id = params[:promotion]
And in the view you can use it in conditions:
<%= render :active_scaffold => 'promotion_spots', :constraints =>
{:account_id => @account.id}, :conditions => "promotion_type_id=#
{...@promotion_id}" %>
If you don't want to use render :active_scaffold you can override list.rhtml
and put the form with the select there and render :super after the form. Then
you can use conditions_for_collection:
def conditions_for_collection
"promotion_type_id=#{params[:promotion]}" if params[:promotion]
end
--
Sergio Cambra .:: entreCables S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---