辅助方法,ActionView和ActionController [英] Helper methods, ActionView and ActionController

查看:96
本文介绍了辅助方法,ActionView和ActionController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在application_contoller.rb中有一个方法,其中包括对send_file的调用.我从javascript呈现的部分代码中调用它,并收到以下错误-

I have a method in application_contoller.rb that includes a call to send_file. I'm calling it from a partial that's rendered by javascript, and getting the following error -

ActionView::Template::Error (undefined method `send_file' for #<#<Class:0x0...

我可以看到发生了什么-send_file是一种控制器方法,因此在我使用它的方式上不可用-我的问题是,如何使它可用?

I can kind of see what's happening - send_file is a controller method, so unavailable in the way I'm using it - my question is, how do I make it available?

推荐答案

您可以在控制器中将方法定义为辅助方法:

You can define your method in controller as helper method:

helper_method :send_file

这篇关于辅助方法,ActionView和ActionController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆