我想新建一个 helper 方法用来添加带有链接的图片,类似于
<a href="http://www.mysite.com"><img src="path/to/image.png"/></a>
我是这么写的
# app/helpers/application_helper.rb
module ApplicationHelper
# a helper method for
# <a href="http://www.mysite.com"><img src="path/to/image.png"/></a>
def link_to_image(image_path, options_img={}, target_link, options_link={})
link_to(image_tag(image_path, options_img), target_link, options_link)
end
end
运行时出现错误
SyntaxError (....app/helpers/application_helper.rb:4: syntax error, unexpected '=', expecting ')'
...={}, target_link, options_link={})
..../app/helpers/application_helper.rb:7: syntax error, unexpected keyword_end, expecting end-of-input):
app/helpers/application_helper.rb:4: syntax error, unexpected '=', expecting ')'
app/helpers/application_helper.rb:7: syntax error, unexpected keyword_end, expecting end-of-input
不知道问题出在哪?是因为 helper 方法的定义出问题了么?