Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何将控制器的方法调用到rails中的视图?_Ruby On Rails_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 如何将控制器的方法调用到rails中的视图?

Ruby on rails 如何将控制器的方法调用到rails中的视图?,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,内部控制器 def test command = 'pwd' result = `#{command}` respond_to do |format| format.html { redirect_to(users_url) } format.js { render :text => "$('#teste').html('#{result}');" } end end 我想显示变量结果 鉴于 <%= link_to 'Testar'

内部控制器

def test
  command = 'pwd'
  result = `#{command}`

   respond_to do |format| 
     format.html { redirect_to(users_url) } 
     format.js { render :text => "$('#teste').html('#{result}');" } 
   end 
end
我想显示变量结果

鉴于

<%= link_to 'Testar', test_users_path, :method => :get, :remote => true  %> 
:get,:remote=>true%>

声明一个helper\u方法

在您的控制器中:

private
def test
  ...
end
helper_method :test

In your view:

<% test -%>
private
def测试
...
终止
方法:测试
在你看来:

我只想在单击按钮后显示退货。