[英]Rails carousel producing 'undefined method `image_path' in controller
I'm trying to make a carousel in a Rails app and can't seem to get around a problem I'm having. 我正在尝试在Rails应用程序中制作轮播,但似乎无法解决我遇到的问题。 I'm new to Rails - so it's probably a simple resolution. 我是Rails的新手,所以这可能是一个简单的解决方案。 This produces a 'undefined method `image_path' in my controller. 这会在我的控制器中产生一个“未定义的方法“ image_path”。 Thanks in advance for any help! 在此先感谢您的帮助!
Here is my controller: 这是我的控制器:
def golf
images = ['CreekCoverLarge.jpg', 'CreekWindmillLarge.jpg', 'CreekExtraLarge.jpg', 'CreekExtra2Large.jpg']
@paths = images.map {|name| image_path name}
end
And this is my view: 这是我的观点:
<div class="item active">
<%= @paths.each do |path| %>
<%= link_to(image_tag(path, class: "img-responsive", size: "600x440"), "#", data: {toggle: "modal", target: "#myModal"}, "onclick"=>"getImage(this)", "data-img-address" => path) %>
<% end %>
</div>
use: 采用:
ActionController::Base.helpers.image_path
Although, cant you just loop through images
in the view and call image_path
there? 虽然,您不能仅浏览视图中的images
并在那里调用image_path
吗?
Edit: 编辑:
Example as requested: 要求的示例:
Controller: 控制器:
def golf
@images = ['CreekCoverLarge.jpg', 'CreekWindmillLarge.jpg', 'CreekExtraLarge.jpg', 'CreekExtra2Large.jpg']
end
View: 视图:
<div class="item active">
<%= @images.each do |path| %>
<%= link_to(image_path(path, class: "img-responsive", size: "600x440"), "#", data: {toggle: "modal", target: "#myModal"}, "onclick"=>"getImage(this)", "data-img-address" => path) %>
<% end %>
</div>
This is untested, but should work. 这未经测试,但应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.