Path for images?

14 views
Skip to first unread message

Jeff

unread,
Aug 15, 2011, 12:33:50 AM8/15/11
to Ruby Reports
I'm trying to set a logo for the top of my reports. In my public/
images directory I have a file called masthead.jpg. In the report
header I have the following:

center_image_in_box "masthead.jpg", but I'm getting a file not found
error. I've tried "images/masthead.jpg", "/images/masthead.jpg",
etc., but to no avail. How do I define the path?

James Silberbauer

unread,
Aug 15, 2011, 4:20:07 AM8/15/11
to ruby-r...@googlegroups.com
Try this:

center_image_in_box Rails.root.join('public','images','masthead.jpg')

Jeff

unread,
Aug 16, 2011, 12:33:02 AM8/16/11
to Ruby Reports
Thanks. Unfortunately now the error I get is "comparison of Fixnum
with nil failed"

Jeff

unread,
Aug 16, 2011, 12:51:34 AM8/16/11
to Ruby Reports
I even tried image_path = Rails.public_path + "/images/masthead.jpg"

and I still get the odd fixnum error.

James Silberbauer

unread,
Aug 16, 2011, 4:08:50 AM8/16/11
to ruby-r...@googlegroups.com
Can you paste your code and the error dump?
Sounds like something else is going wrong - do you provide x, y, width
or height parameters to center_image_in_box?

Jeff

unread,
Aug 16, 2011, 11:47:34 PM8/16/11
to Ruby Reports
Are those required options? I haven't been providing them, assuming
the box would simply be the size of the image.

Jeff

unread,
Aug 17, 2011, 12:34:40 AM8/17/11
to Ruby Reports
Here's the errant code:

module StandardBookMobileReport
def build_standard_report_header
image_path = Rails.public_path.to_s + "/images/masthead.jpg"
center_image_in_box image_path
end
end

If I comment out the center_image bit I have no problems.

Here's the relevant log:

ArgumentError (comparison of Fixnum with nil failed):
app/reports/StandardBookMobileReport.rb:4:in
`build_standard_report_header'
app/controllers/reports_controller.rb:34:in `lowInventoryReport'

Jeff

unread,
Aug 27, 2011, 10:33:12 PM8/27/11
to Ruby Reports
So, yes, those options aren't exactly optional it would appear. Once
I supply them the image is attached - not exactly where I expected,
but its a start. :)

On Aug 16, 8:47 pm, Jeff <jlee...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages