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

ca01ei · December 11, 2016 · Last by ca01ei replied at December 11, 2016 · 1662 hits

我想新建一个 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 closed this topic. 11 Dec 13:26
You need to Sign in before reply, if you don't have an account, please Sign up first.