mathieu bougie
unread,May 28, 2012, 9:24:13 AM5/28/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Core
I want to clean my code by moving the duplicated lines :
partial = render_to_string( :partial => "#{file}", :formats =>
[:html] )
to the pagination_partials function.
=================================================
WORKING CODE:
=================================================
def render_format_search_partial(file, options={})
# TODO remove this line to use the one in the
pagination_partials function
partial = render_to_string( :partial => "#{file}", :formats =>
[:html] )
respond_to do |format|
format.json { render :json => pagination_partials(file,
partial, options), :status => 200 }
format.html
end
end
def render_json_search_partial(file, options={})
# TODO remove this line to use the one in the
pagination_partials function
partial = render_to_string( :partial => "#{file}", :formats =>
[:html] )
render :json => pagination_partials(file, partial,
options), :status => 200
end
def pagination_partials(file, partial, options={})
# TODO use this line instead of the duplicated lines above
#partial = render_to_string( :partial => "#{file}", :formats =>
[:html] )
pagination = render_to_string( :partial => 'shared/list/
will_paginate', :formats => [:html] )
hash = {:response => partial, :pagination => pagination}
options.each { |o, v| hash.merge(o => v) unless options.blank? }
hash
end
=====================================================
WORKING CODE:
=====================================================
def render_format_search_partial(file, options={})
partial = pagination_partials(file, options)
respond_to do |format|
format.json { render :json => partial, :status => 200 }
format.html
end
end
def render_json_search_partial(file, options={})
partial = pagination_partials(file, options)
render :json => partial, :status => 200
end
def pagination_partials(file, options={})
partial = render_to_string( :partial => "#{file}", :formats =>
[:html] )
pagination = render_to_string( :partial => 'shared/list/
will_paginate', :formats => [:html] )
hash = {:response => partial, :pagination => pagination}
options.each { |o, v| hash.merge(o => v) unless options.blank? }
hash
end
===============================================
EXPECTED WORKING CODE....but it doesnt work
===============================================
def render_format_search_partial(file, options={})
respond_to do |format|
format.json { render :json => pagination_partials(file,
options), :status => 200 }
format.html
end
end
def render_json_search_partial(file, options={})
render :json => pagination_partials(file, options), :status =>
200
end
def pagination_partials(file, options={})
partial = render_to_string( :partial => "#{file}", :formats =>
[:html] )
pagination = render_to_string( :partial => 'shared/list/
will_paginate', :formats => [:html] )
hash = {:response => partial, :pagination => pagination}
options.each { |o, v| hash.merge(o => v) unless options.blank? }
hash
end
============================================================
WILL_PAGINATE PARTIAL:
============================================================
<div class="pagination_wrapper">
<%= will_paginate @search_result, :page_links => false,
:previous_label => "#{image_tag
'icons/control-180.png', :class => "prev-button link-button link-
button-small"}",
:next_label => "#{image_tag 'icons/
control.png', :class => "next-button link-button link-button-small"}"
%>
</div>
============================================================
THE EVIL PARTIAL (users/user_list):
============================================================
<div class="list-table" data-source="<%=
search_enterprise_users_path(@enterprise, :format => :html) %>">
<%= render( :partial => 'user',
:collection => @search_results,
:spacer_template => 'shared/list/separator') ||
t('user.empty_result') %>
</div>
============================================================
THE ERROR:
============================================================
ActionView::MissingTemplate (Missing partial users/user_list with
{:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee, :haml]}.
Searched in:...
============================================================
I think something's wrong when I try to render a partial inside
another, I tried to remove the spacer_template in the render user
partial and i also try to add the formats => [:html] inside the render
block but without success....It will render properly only if I remove:
<%= render( :partial => 'user',
:collection => @search_results,
:spacer_template => 'shared/list/separator') ||
t('user.empty_result') %>
I don't know if some one can reproduce this issue but I'm interesting
to get some clue about this bug
Thx