新手问题 新建一个 application helper 方法出现错误

ca01ei · 2016年12月11日 · 最后由 ca01ei 回复于 2016年12月11日 · 1659 次阅读

我想新建一个 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 方法的定义出问题了么?

有默认值的参数必须放在没有默认值的参数后面。

额。。忘记这个了,多谢。

ca01ei 关闭了讨论。 12月11日 13:26
需要 登录 后方可回复, 如果你还没有账号请 注册新账号