ruby on rails - Add Methods to Iterated Objects -
i have block looks similar one:
<% @github_tmp_files.files.each |file| %> <li><%= link_to @github_tmp_files.filename(file.key), @github_tmp_files.download_url(file.key) %></li> <% end %>
as can see in loop call 2 methods file
argument:
@github_tmp_files.filename(file.key) @github_tmp_files.download_url(file.key)
i prefer call 2 methods that:
file.filename (should return) @github_tmp_files.filename(file.key) file.download_url (should return) @github_tmp_files.download_url(file.key)
so @ end can write loop this:
<% @github_tmp_files.files.each |file| %> <li><%= link_to file.filename, file.download_url %></li> <% end %>
how have change files
method in @github_tmp_files
, allows behaviour? thanks
#in @github_tmp_files -> class def files github_bucket.objects(prefix: @folder) end
just out of curiosity:
<% @github_tmp_files.files.map(&:key).each |file| %> <li> <%= link_to *[:filename, :download_url].each |m| @github_tmp_files.public_send(m, file) end %> </li> <% end %>
Comments
Post a Comment