why isn't my :unless Proc stopping this primary.item from displaying?

25 views
Skip to first unread message

Steven Noble

unread,
Dec 16, 2012, 11:21:59 PM12/16/12
to simple-n...@googlegroups.com
In navigation.rb I have:

primary.item :areas, "areas", report_areas_path(@report), :unless => Proc.new {@report.nil?}

So how can I be getting the following error when I render_navigation?

No route matches {:controller=>"areas", :report_id=>nil}

Thanks,

Steven.

mjtko

unread,
Dec 17, 2012, 4:22:45 AM12/17/12
to simple-n...@googlegroups.com
Hi Steven,

The :unless/:if options allow modification of the rendering, but do not prevent any methods from being called to generate the URLs etc.  You probably want this incantation instead:

primary.items :areas, "areas", report_areas_path(@report) unless @report.nil?

Cheers,

Mark. 

Andi Schacke

unread,
Dec 17, 2012, 4:39:42 AM12/17/12
to simple-n...@googlegroups.com
Hi Steven,

the config file is pure ruby and evaluated like any normal source
file, at the beginning of each render process. So the :unless block
just tells simple-navigation not to render the item if @report is nil,
but it cannot stop the report_areas_path method from being evaluated.
So if you want to avoid the error, you have to do it using a proper
unless statement:

unless @report.nil?
primary.item :areas, "areas", report_areas_path(@report)
end

Andi
> --
> You received this message because you are subscribed to the Google Groups
> "simple-navigation" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/simple-navigation/-/zsLOTvTLZOYJ.
> To post to this group, send email to simple-n...@googlegroups.com.
> To unsubscribe from this group, send email to
> simple-navigat...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/simple-navigation?hl=en.

Steven Noble

unread,
Dec 17, 2012, 4:46:13 AM12/17/12
to simple-n...@googlegroups.com
Thanks. That makes sense.

Steven.
---
Steven Noble
Founder & CEO, Testivate
http://testivate.com | +61 (0) 4 0404 1928 | http://snoble.net

Reply all
Reply to author
Forward
0 new messages