Anybody?
I know which piece of code i need to manipulate but im not sure how to
do it in the
helper. So what ive done is copy the below from the the plugin folder
and placed it in my helper.
So i know for the first line column.association.name is effectively
"surveys" but struggling on the rest?
def surveys_form_column(record, input_name)
associated_options = @record.send
(column.association.name).collect {|r| [r.to_label, r.id]}
select_options = associated_options | options_for_association
(column.association)
return 'no options' if select_options.empty?
html = "<ul class=\"checkbox-list\" id=\"#{options[:id]}\">"
associated_ids = associated_options.collect {|a| a[1]}
select_options.each_with_index do |option, i|
label, id = option
this_name = "#{options[:name]}[#{i}][id]"
this_id = "#{options[:id]}_#{i}_id"
html << "<li>"
html << check_box_tag(this_name, id, associated_ids.include?
(id), :id => this_id)
html << "<label for='#{this_id}'>"
html << label
html << "</label>"
html << "</li>"
end
html << '</ul>'
html << javascript_tag("new DraggableLists('#{options
[:id]}')") if column.options[:draggable_lists]
html
end
On Jan 12, 9:09 am, johnnybutler7 <[email protected]> wrote:
> Thanks for reply,
>
> 1)Yes ive used helpers to override columns but cant seem to get the
> multi-check-box to work. Is there any examples kicking
> about?
>
> 2) What i mean by extra sql keys is there any way i can add custom
> joins or an order_by clause for example in the
> options_for_association_conditions.
>
> So something like my example below:
> if association.name == :surveys
> company_id = @record.primary_survey.user.company_id
> :joins => 'blah...............,
> :conditions => ["users.company_id = ?",company_id],
> :order_by => ["users.name ASC]
> else
> super
> end
>
> I know i could set the default order on the model but say i wanted a
> custom order by and include another join.
>
> At the moment it looks like we can just add conditions in
> options_for_association_conditions as per below
>
> def options_for_association_conditions(association)
> if association.name == :surveys
> client_id = @record.primary_survey.user_id
> ["surveys.user_id = ?",client_id]
> else
> super
> end
>
> JB
>
> On Jan 7, 3:08 pm, "mr.gaffo" <[email protected]> wrote:
>
> > 1) Use a helper column override.
> > 2) what do you mean by extra "sql keys"? Tables? Params mapping to ? ?
>
> > On Jan 6, 7:32 am, johnnybutler7 <[email protected]> wrote:
>
> > > Hi,
>
> > > A few questions on this that im stuck on, hopefully someone can help
> > > me out.
>
> > > 1)I have the following code below which gives a multiple checkboxes
> > > which is what i want,
>
> > > config.columns[:surveys].ui_type = :select
>
> > > I have a column called name on the surveys model which it defaults to
> > > but i want to change this to
> > > #{surveys.name} #{surveys.score} but i dont want to overide the
> > > to_label method as this model is used in other active scaffolds where
> > > i want just the name displayed and not the score. Whats the easiest
> > > way to this?
>
> > > 2) For the same column i want to filter what surveys are diaplyed
> > > depending on what the company of the user is.
> > > So i have :
>
> > > def options_for_association_conditions(association)
> > > if association.name == :surveys
> > > client_id = @record.primary_survey.user_id
> > > ["surveys.user_id = ?",client_id]
> > > else
> > > super
> > > end
>
> > > This works fine however i really want it so it displays all surveys
> > > that belong to a users company so something like:
>
> > > def options_for_association_conditions(association)
> > > if association.name == :surveys
> > > company_id = @record.primary_survey.user.company_id
> > > :joins => 'blah...............,
> > > :conditions => ["users.company_id = ?",company_id],
> > > else
> > > super
> > > end
>
> > > Is there any way to add extra sql keys aswell as the conditions?
>
> > > thanks
>
> > > JB
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---