问题
I have a method in my controller class
class ProjectsController < ApplicationController
def download_sftp
some codes here
end
end
and to be able to access it in my view,at the top of my controller I have this line
helper_method :download_sftp
when I use the following code in my view I get the undefined method download_sftp for this project
<tbody>
<% @projects.each do |project| %>
<tr>
<td><%= link_to 'download',project.download_sftp(project) %></td>
</tr>
<% end %>
</tbody>
回答1:
declaring a helper_method on a controller will make it available in a view directly like any other helper (e.g form_for or link_to). However you are calling this on a project model.
So it should be:
<td><%= link_to 'download', download_sftp(project) %></td>
What is download_sftp supposed to do? Perhaps it even belongs into the project model.
来源:https://stackoverflow.com/questions/24993912/share-method-in-view-and-controller-ruby-on-rails-4