Hello!
icons which has three subfolders - controllers, png and svg. input.haml. controllers, I have file images_controller.rbHere is the sample of input.haml:
%div{style:"background-color: #fff; color:#000; width: 256px"}
%br/
%p Using local images path in loop arrays
- @images.each do |image|
%img{:src => "png/#{image.split('/').last}.png", style:"height: 64px; width: 64px; padding: 5px;"}
And of images_controllers.rb:
before_filter :set_input, only: %w(new create)
def set_input
@images = Dir.glob('/home/gusbemacbe/icons/png/*.png')
end
I ran haml input.haml output.html
But I got an error:
Exception on line 5: undefined method `each' for nil:NilClass
Paweł Świątkowski
Elixir developer with Ruby past
When you run
hamlfrom command line, it has no knowledge about your controller.set_inputmethod was never called and therefore@imagesinstance variable was never set (so it'snil). It looks like you are trying to use HAML in Rails context sou you should actually perform a request to you local server that will call the controller, which will set@imagesvariable and then render HAML view.