&quote and add_associated_link

5 views
Skip to first unread message

Shumkov

unread,
Jan 5, 2009, 10:45:39 AM1/5/09
to attribute_fu
_fields.html :

<div id="event_links">
<%= fields.render_associated_form(@event.links, :partial =>
'link', :new => 1) %>
</div>
<div class="submit-field">
<%= fields.add_associated_link('Add links',
@event.links.build, :partial => 'link', :class => 'add') %>
</div>

_link.html :

<div class="event_link">
<%= f.collection_select :site_id, Site.find
(:all), :id, :title, :label => 'Site', :object => link, :prompt => ''
%>
<%= f.text_field :url, :label => 'Link to event', :class => 'long'
%>
<div class="submit-field">
<%= f.remove_link "Delete", :class => 'delete' %>
</div>
</div>

If i'm have site with quote in title, when i'm click "Add links" i'm
see javascript error "missing ] after element list". This is problem
with escaping in "add_associated_link" method in "new Template".

Shumkov

unread,
Jan 5, 2009, 11:03:56 AM1/5/09
to attribute_fu
Forget: Rails 2.2.2 and attribute_fu lastest from github

Shumkov

unread,
Jan 12, 2009, 5:43:04 AM1/12/09
to attribute_fu
Solution:

def render_associated_form(associated, opts = {})
associated = associated.is_a?(Array) ? associated : [associated]
# preserve association proxy if this is one

opts.symbolize_keys!
(opts[:new] - associated.select(&:new_record?).length).times
{ associated.build } if opts[:new]

unless associated.empty?
name = extract_option_or_class_name(opts, :name,
associated.first)
partial = opts[:partial] || name
local_assign_name = partial.split('/').last.split('.').first

associated.map do |element|
fields_for_associated(element, (opts[:fields_for] ||
{}).merge(:name => name)) do |f|
template = @template.render({:partial => "#
{partial}", :locals => {local_assign_name.to_sym => element, :f =>
f}.merge(opts[:locals] || {})}.merge(opts[:render] || {}))
template.gsub!('&', '&amp;') if opts[:fields_for] && opts
[:fields_for][:javascript]
template
end
end
end
end

This line is important: template.gsub!('&', '&amp;') if opts
[:fields_for] && opts[:fields_for][:javascript]

On 5 янв, 18:45, Shumkov <ivanshum...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages