S. Faust
S. Faust

Reputation: 17

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. I'm new to Rails - so it's probably a simple resolution. This produces a 'undefined method `image_path' in my controller. 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>

Upvotes: 1

Views: 1227

Answers (1)

DickieBoy
DickieBoy

Reputation: 4956

use:

ActionController::Base.helpers.image_path

Although, cant you just loop through images in the view and call image_path there?

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.

Upvotes: 2

Related Questions