Rails 3.1 render :super error

106 views
Skip to first unread message

blmundie

unread,
Sep 21, 2011, 4:15:01 PM9/21/11
to ActiveScaffold : Ruby on Rails plugin
I'm getting an error when calling render :super in rails 3.1.

ActionView::Template::Error (You have a nil object when you didn't
expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.last):
19:
20:
21:
22: <%= render :super %>
/home/bryan/.rvm/gems/ruby-head/bundler/gems/
active_scaffold-0ce03559d49f/lib/active_scaffold/extensions/
action_view_rendering.rb:42:in `render_with_active_scaffold'
app/views/installation_alarms/list.html.erb:22:in
`_app_views_installation_alarms_list_html_erb__1059381062_93896420'


seems like activescaffold is looking for @_view_stack which is nil.
https://github.com/activescaffold/active_scaffold/blob/master/lib/active_scaffold/extensions/action_view_rendering.rb
line 42

blmundie

unread,
Sep 21, 2011, 6:57:06 PM9/21/11
to ActiveScaffold : Ruby on Rails plugin
If i set the template to render a partial that render :super I get
past the above error. It then gives me a new error. I get is
ActionView::Template::Error (undefined method `map' for
"installations":String):
18: ")%>
19:
20:
21: <%= render :super %>
actionpack (3.1.0) lib/action_view/lookup_context.rb:129:in
`normalize_name'
actionpack (3.1.0) lib/action_view/lookup_context.rb:114:in
`args_for_lookup'
/home/bryan/.rvm/gems/ruby-head/bundler/gems/
active_scaffold-5c4ae3b25238/lib/active_scaffold/extensions/
action_view_rendering.rb:7:in `block (2 levels) in find_all_templates'

installations is the name of my model.
> seems like activescaffold is looking for @_view_stack which is nil.https://github.com/activescaffold/active_scaffold/blob/master/lib/act...
> line 42

blmundie

unread,
Sep 22, 2011, 7:25:13 PM9/22/11
to ActiveScaffold : Ruby on Rails plugin
This only happens when i use render :super in list.html.erb. Does
anyone have an idea?

blmundie

unread,
Sep 23, 2011, 4:27:05 PM9/23/11
to ActiveScaffold : Ruby on Rails plugin
Best I can tell there are two issue. The first is
args_for_lookup(name, prefixes, partial, keys) calls .map on prefixes
and activescaffold is passing a single prefix as a string. Map is not
a documented method for String. It works on String on my 1.8.7
install but not 1.9+. To fix this I changed find_all_templates in
active scaffold to. This sends prefix as an array and gets the string
out from the return. I'm not sure this is the ideal solution, but it
works.

class LookupContext
module ViewPaths
def find_all_templates(name, partial = false, locals = {})
prefixes.collect do |prefix|
view_paths.collect do |resolver|
temp_args = *args_for_lookup(name, [prefix], partial,
locals )
temp_args[1] = temp_args[1][0]
resolver.find_all(*temp_args)
end
end.flatten!
end
end
end

The second issue I've run into is that @_view_stack is nil if I call
render :super in the first view and not the partial. Seems like the
stack only gets added to from render called in the view. Therefor I
get an error when I call render :super in list.html.erb, but not if I
call it in _list.html.erb.

Sergio Cambra .:: entreCables S.L. ::.

unread,
Sep 28, 2011, 8:56:35 AM9/28/11
to actives...@googlegroups.com
On Viernes, 23 de Septiembre de 2011 22:27:05 blmundie escribió:
> Best I can tell there are two issue. The first is
> args_for_lookup(name, prefixes, partial, keys) calls .map on prefixes
> and activescaffold is passing a single prefix as a string. Map is not
> a documented method for String. It works on String on my 1.8.7
> install but not 1.9+. To fix this I changed find_all_templates in
> active scaffold to. This sends prefix as an array and gets the string
> out from the return. I'm not sure this is the ideal solution, but it
> works.

Thanks, I missed this one becuase I use 1.8.7, although I'm not sure why it
worked.

>
> class LookupContext
> module ViewPaths
> def find_all_templates(name, partial = false, locals = {})
> prefixes.collect do |prefix|
> view_paths.collect do |resolver|
> temp_args = *args_for_lookup(name, [prefix], partial,
> locals )
> temp_args[1] = temp_args[1][0]
> resolver.find_all(*temp_args)
> end
> end.flatten!
> end
> end
> end
>
> The second issue I've run into is that @_view_stack is nil if I call
> render :super in the first view and not the partial. Seems like the
> stack only gets added to from render called in the view. Therefor I
> get an error when I call render :super in list.html.erb, but not if I
> call it in _list.html.erb.

I have fixed it. I dislike this fix because it uses a internal variable, which
could be removed in a later version, but render :super it's really a hack too,
so another hack more is not very important.

--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) ser...@entrecables.com

blmundie

unread,
Sep 28, 2011, 9:09:17 PM9/28/11
to ActiveScaffold : Ruby on Rails plugin
Thanks for the help. The fix fixed the render :super for the first
layer "list.html.erb". It still has the error in 1.9 for me. You
changed prefix to [prefix]. This makes args_for_lookup return prefix
as an array when resolver.find_all is looking for a string. I just
took the results of args_for_lookup and changed prefix to the first
element returned in the prefix array. I know it's kind of hacky but
it works.

class LookupContext
module ViewPaths
def find_all_templates(name, partial = false, locals = {})
prefixes.collect do |prefix|
view_paths.collect do |resolver|
temp_args = *args_for_lookup(name, [prefix], partial,
locals )
temp_args[1] = temp_args[1][0]
resolver.find_all(*temp_args)
end
end.flatten!
end
end
end

On Sep 28, 8:56 am, "Sergio Cambra .:: entreCables S.L. ::."

Sergio Cambra .:: entreCables S.L. ::.

unread,
Sep 29, 2011, 5:44:07 AM9/29/11
to actives...@googlegroups.com
On Jueves, 29 de Septiembre de 2011 03:09:17 blmundie escribió:
> Thanks for the help. The fix fixed the render :super for the first
> layer "list.html.erb". It still has the error in 1.9 for me. You
> changed prefix to [prefix]. This makes args_for_lookup return prefix
> as an array when resolver.find_all is looking for a string. I just
> took the results of args_for_lookup and changed prefix to the first
> element returned in the prefix array. I know it's kind of hacky but
> it works.
>
> class LookupContext
> module ViewPaths
> def find_all_templates(name, partial = false, locals = {})
> prefixes.collect do |prefix|
> view_paths.collect do |resolver|
> temp_args = *args_for_lookup(name, [prefix], partial,
> locals )
> temp_args[1] = temp_args[1][0]
> resolver.find_all(*temp_args)
> end
> end.flatten!
> end
> end
> end

Thanks. Probably it's very hacky, but I can't find a better way to get all
templates. Previously we shifted view paths for each render :super, so used
view_paths was ignored. But search is nested iteration, so it doesn't work
now.

I hope lookup templates code won't change in next rails versions

Adam Spiers

unread,
Jan 28, 2012, 12:26:35 PM1/28/12
to actives...@googlegroups.com
I just upgraded from Rails 3.1.3 to 3.2.1 and now render :super breaks my tests:

E
===================================================================================================
Error:
test_should_get_index(Admin::RolesControllerTest):
ActionView::Template::Error: wrong number of arguments (4 for 5)
    app/views/admin/roles/list.html.haml:5:in `_app_views_admin_roles_list_html_haml___368318457_75996840'
    lib/admin/controller_tests.rb:68:in `block in <module:Index>'
===================================================================================================

Here's the stack trace:
actionpack (3.2.1) lib/action_view/lookup_context.rb:137:in `args_for_lookup'
active_scaffold (3.1.18) lib/active_scaffold/extensions/action_view_rendering.rb:7:in `block (2 levels) in find_all_templates'
actionpack (3.2.1) lib/action_view/path_set.rb:38:in `each'
actionpack (3.2.1) lib/action_view/path_set.rb:38:in `each'
active_scaffold (3.1.18) lib/active_scaffold/extensions/action_view_rendering.rb:6:in `collect'
active_scaffold (3.1.18) lib/active_scaffold/extensions/action_view_rendering.rb:6:in `block in find_all_templates'
active_scaffold (3.1.18) lib/active_scaffold/extensions/action_view_rendering.rb:5:in `collect'
active_scaffold (3.1.18) lib/active_scaffold/extensions/action_view_rendering.rb:5:in `find_all_templates'
active_scaffold (3.1.18) lib/active_scaffold/extensions/action_view_rendering.rb:49:in `render_with_active_scaffold'
haml (3.1.4) lib/haml/helpers/action_view_mods.rb:11:in `block in render_with_haml'
haml (3.1.4) lib/haml/helpers.rb:90:in `non_haml'
haml (3.1.4) lib/haml/helpers/action_view_mods.rb:11:in `render_with_haml'

I notice someone updated the wiki in February 2011 to say that render :super doesn't work for HAML, only ERB, but it was working fine for me until the upgrade.

Any ideas?  Thanks!

P.S. the only reason I need render :super is to invoke my title helper to set the page title.  Is there another way to do that?

ser...@entrecables.com

unread,
Jan 30, 2012, 8:06:16 AM1/30/12
to actives...@googlegroups.com
On Sat, 28 Jan 2012 09:26:35 -0800 (PST), Adam Spiers
<adam....@gmail.com> wrote:
> I just upgraded from Rails 3.1.3 to 3.2.1 and now render :super breaks
> my tests:
>
> E
> ===================================================================================================
> Error:
> test_should_get_index(Admin::RolesControllerTest):
> ActionView::Template::Error: wrong number of arguments (4 for 5)
> app/views/admin/roles/list.html.haml:5:in
> `_app_views_admin_roles_list_html_haml___368318457_75996840'
> lib/admin/controller_tests.rb:68:in `block in '
> I notice someone updated the wiki in February 2011 [1] to say that

> render :super doesn't work for HAML, only ERB, but it was working fine
> for me until the upgrade.
> Any ideas? Thanks!
>
> P.S. the only reason I need render :super is to invoke my title helper
> to set the page title. Is there another way to do that?

You can try with config.label or config.list.label in a before filter,
but it could not be enough if you need to set html tags for example.

I have fixes rails 3.2 issues, I will release a new version tomorrow.

>
> --
> You received this message because you are subscribed to the Google
> Groups "ActiveScaffold : Ruby on Rails plugin" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/activescaffold/-/P3xFEkkxyR0J [2].
> To post to this group, send email to actives...@googlegroups.com.
> To unsubscribe from this group, send email to
> activescaffol...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/activescaffold?hl=en.
>
>
> Links:
> ------
> [1]
> https://github.com/activescaffold/active_scaffold/wiki/Template-Overrides/_compare/9e1cb62a776d84499db7ed6d62c75d9a0a7efc4a...1b68b78c8629c7f6d2c233a7a673a97b2a8915fe
> [2] https://groups.google.com/d/msg/activescaffold/-/P3xFEkkxyR0J

Adam Spiers

unread,
Jan 30, 2012, 8:45:07 AM1/30/12
to actives...@googlegroups.com
On Mon, Jan 30, 2012 at 1:06 PM, <ser...@entrecables.com> wrote:
>> P.S. the only reason I need render :super is to invoke my title helper
>> to set the page title. Is there another way to do that?
>
> You can try with config.label or config.list.label in a before filter,
> but it could not be enough if you need to set html tags for example.

Sorry - by page title I meant <title> not the <h2>. I guess I could
do that with a before filter, but then it couldn't change per action.

> I have fixes rails 3.2 issues, I will release a new version tomorrow.

Thanks :)

Sergio Cambra

unread,
Jan 31, 2012, 5:00:30 AM1/31/12
to actives...@googlegroups.com
On Lunes, 30 de enero de 2012 13:45:07 Adam Spiers escribió:
> On Mon, Jan 30, 2012 at 1:06 PM, <ser...@entrecables.com> wrote:
> >> P.S. the only reason I need render :super is to invoke my title helper
> >> to set the page title. Is there another way to do that?
> >
> > You can try with config.label or config.list.label in a before filter,
> > but it could not be enough if you need to set html tags for example.
>
> Sorry - by page title I meant <title> not the <h2>. I guess I could
> do that with a before filter, but then it couldn't change per action.

You can change per action with a before_filter, testing action_name and setting
an instance variable. Also you can use a helper method in your layout to set
the title. Or override the index action. It's up to you, but there are some
options. Maybe using a helper method has better performance than overriding
list view and using render :super.


Adam Spiers

unread,
Jan 31, 2012, 9:29:11 AM1/31/12
to actives...@googlegroups.com
On Tue, Jan 31, 2012 at 10:00 AM, Sergio Cambra <ser...@entrecables.com> wrote:
> You can change per action with a before_filter, testing action_name and setting
> an instance variable. Also you can use a helper method in your layout to set
> the title. Or override the index action. It's up to you, but there are some
> options. Maybe using a helper method has better performance than overriding
> list view and using render :super.

Thanks, I'll give those ideas a go :)

Reply all
Reply to author
Forward
0 new messages