-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi Matt:
Thanks for the answer. As a workaround I tried not to get a hash, and
finally I change my query from:
Model.count(:all, :joins => {:model1,:model2}, :group => "model2.name")
to
Model.find(:all, :joins => {:model1,:model2}, :select => 'count(*) AS
count, model2.name AS my_name', :group => 'model2.name')
This change ("find" instead of "count") gives us the chance to use
"my_name" and "count" in fields part of table-plus :)
Cheers, Ibon.
Usa Software Libre, tus úlceras te lo agradecerán
Realizado con Software Libre.
- --
GPG public key at http://sinanimodelucro.net/ibon_gmail.asc
Finderprint: 1761 59B9 6DE6 0402 31B9 1872 178F A6FD 75F9 EB29
El 03/02/11 01:43, Matt Jones escribió:
>
> On Feb 2, 2011, at 3:11 AM, txapelgorri wrote:
>
>> Hi there:
>>
>> I'm trying to show some results using the presentation benfits of
>> table-plus (or table). I make an answer to the database, and I get the
>> result back as a hash. I find this previous question on this list:
>>
>> http://groups.google.com/group/hobousers/browse_thread/thread/7a1a807ff02e656c/eab0b805512339bd?lnk=gst&q=tableplus+hash#eab0b805512339bd
>>
>> ...but still I can't figure out how to convert my key/value pairs in
>> something that table-plus could understand :S
>
> Getting table-plus to work is going to be painful - there are quite a few
> assumptions in that code that you're passing in AR models.
>
> Depending on what you're doing, you might just be able to use the built-in
> behavior of the repeat attribute on hashes. Example, assuming there's a hash
> in @stuff:
>
> <table>
> <tr>
> <th>Key</th>
> <th>Value</th>
> </tr>
> <tr repeat="&@stuff">
> <td><%= this_key %></td>
> <td><%= this %></td>
> </tr>
> </table>
>
> The repeat option above puts each value in 'this' and the corresponding key
> in 'this_key'.
>
> Another possibility, if you're getting a hash where the values are
> ActiveRecord models, would be to convert the hash to an array with the keys
> in accessors. Example:
>
> (on the model):
>
> attr_accessor :key_data, :type => :string # or whatever type is correct
>
> (in the controller)
> @hash_stuff = ...get the hash...
> @hash_array = @hash_stuff.to_a.inject([]) { |a, x| x[1].key_data = x[0]; a <<
> x[1]; a }
>
> The result will be a plain array of ActiveRecord models; the key from the
> original hash will be available as a 'key_data' field for table/table-plus
> etc.
>
> --Matt Jones
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAk1KhdsACgkQF4+m/XX56ymmZgCfeQXwhFwdkMEIUJXSfCAzpkD6
K2EAoJ57QTa1paktwsyzIbW7CKdZO4XT
=Yrjt
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.