share method in view and controller ruby on rails 4

妖精的绣舞 提交于 2020-01-14 05:23:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!