On Viernes, 5 de Febrero de 2010 12:21:05 Benjamin Adler escribió: > On Thursday 04 February 2010 09:34:14 Sergio Cambra .:: entreCables S.L. > ::. > the two problems remain: > > a) instead of showing C's name in the table, I get values like > "#<C:0x7f63f3dc4ed0>" in the cells, and I don't know how to specify that > not "C", but rather "C.name" should be displayed
You can define to_label method and it will be used, but if model C has a name column it should be already used. > > b) When searching, the extension specified in joins_for_collection (is that > override documented somewhere? google isdn't really helpful) seems to be > ignored. At least, I don't see the corresponding SQL being passed to mysql > in script/server's log. What is joins_for_collection supposed to return, an > array with strings? If not, how do I return multiple joins? It is an array of associations or a string to use in sql query. It's used as :joins option of ActiveRecord find method. Look for all available formats in Ruby on Rails API. Do you have latest ActiveScaffold? If you don't, what is the code for joins_for_finder method in your copy of vendor/plugins/active_scaffold/lib/active_scaffold/finder.rb? > > Also, what would a join_for_collection for a habtm-association look like? > In my case, B also habtm D, how can I show all Ds in A's table? Sorry to > ask these probably basic questions, but I couldn't find any documentation > on joins_for_collection. You will have to add two joins one for chaining table and one for D table. You can include rails associations in joins_for_collection but then Rails will do a inner join. Also you can include them in active_scaffold_includes, but all fields from these tables will be loaded too (columns will be included in the select). You can try with these options and look at the query in the log. If you are in development environment you will have the query in your development.log > > Just for completeness, here are my models and controllers. A is > available_tubes, B ist catalog_items, C is conjugates (and D is > reactivities, but other than being habtm its really not worth showing) > > class AvailableTube < ActiveRecord::Base > belongs_to :catalog_item > belongs_to :user > belongs_to :storage, :class_name => '::Storage' > delegate :conjugate, :manufacturer, :to => :catalog_item > > def name > catalog_item.name + " - " + user.name + " - " + storage.name > end > end > > class AvailableTubesController < ApplicationController > active_scaffold :available_tube do |config| > config.columns << :conjugate > config.columns[:conjugate].search_sql = 'conjugate.name' > > def joins_for_collection > "LEFT JOIN conjugates ON catalog_items.conjugate_id=conjugate.id" > end > end > end You have to add conjugate to config.search.columns too -- Sergio Cambra .:: entreCables S.L. ::. Mariana Pineda 23, 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.
