Table plus (and table btw) have a fields attribute that you could
theoretically generate but usually it's going to expect there to at
least be a method on the model that responds. Also, I'm not sure the
data you're talking about is something best stuck in a table unless
there's always x number of event kinds.
wait.. you've basically got a set table of event kinds and want to
have a column for each that pulls the appropriate company event. add
a named_scope to company model that grabs event based on event kind id
and a function to return name calls for each (otherwise it gets ugly),
then you can do something like this.
def event_model_list
list = []
EventKind.all.each { |ek| list << "event_by_kind(#{ek.id})" }
list
end
fields="regularfields,#{event_model_list.join(',')}" will get you a
column for each but defining each view
still pretty ugly but might work for what you're after.
On Mar 1, 8:18 pm, François Beausoleil <[email protected]>
wrote:
> Hi all!
>
> I have events, event kinds and companies:
>
> Company has_many :events
> Event belongs_to :company
> Event belongs_to :event_kind
>
> I'm generating a report sheet / progress chart for my users. Rows are
> companies, and columns are event kinds. My code is ugly, but works. I
> want to beautify it. Here's the current look (SPOILER: ugly, ugly,
> ugly):http://gist.github.com/319083
>
> <table-plus with="&@companies" fields="&@fields">
> <event-kind-1-heading-link:>
> <%=h @event_kinds.detect {|ek| ek.id == 1}.name %>
> </event-kind-1-heading-link:>
> <event-kind-1-view:>
> <a if="&this" with="&@events[this.to_i]"><%= this ?
> this.created_at.to_date.to_s(:short) : nil %></a>
> </event-kind-1-view:>
>
> <event-kind-2-heading-link:>
> <%=h @event_kinds.detect {|ek| ek.id == 2}.name %>
> </event-kind-2-heading-link:>
> <event-kind-2-view:>
> <a if="&this" with="&@events[this.to_i]"><%= this ?
> this.created_at.to_date.to_s(:short) : nil %></a>
> </event-kind-2-view:>
> </table-plus>
>
> This is all boiler plate. I'm sure I can automatically generate this.
> If I were using plain jane Rails, I'd have a partial to which I'd pass
> options. My problem stems from the fact that table-plus expects to
> have child attributes which match the field names. Notice I have a
> @fields ivar which at least tells me which columns are expected.
>
> So? How can I programatically generate columns for table-plus?
>
> Thanks!
> François
--
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.