jjzjj

get_collection

全部标签

ruby-on-rails - rails "undefined method for ActiveRecord_Associations_CollectionProxy"

我有这个模型:classStudent如果我在我的movies_controller.rb中写这个:@students=@movie.cinema.companies.students.all我有这个错误:#Company::ActiveRecord_Associations_CollectionProxy:0x00000007f13d88的未定义方法“学生”>如果我这样写:@students=@movie.cinema.companies.find(6).students.all它向我显示了我的select_collection中的正确学生。如何更好地理解这个过程?更新:我需要这部电

ruby-on-rails - 将 header 添加到 rspec get

我是rspec的新手-据说!我正在尝试将jwttoken传递给get请求。我看到好几篇帖子都说语法是:获取:端点,参数:{},header:{}这就是我所做的:require'rails_helper'require"rack/test"includeRack::Test::Methodsdefauthenticated_header(user,password)response=AuthenticateUser.call(user,password){"Authorization"=>response.result}endRSpec.describeApi::AlbumsContro

ruby-on-rails - 使用 OpenURI 或 net/http 的 Ruby 代理身份验证 GET/POST

我正在使用ruby​​1.9.3并尝试使用open-uri获取url并尝试使用Net:HTTP发布我正在尝试对两者使用代理身份验证:尝试使用net/http执行POST请求:require'net/http'require'open-uri'http=Net::HTTP.new("google.com",80)headers={'User-Agent'=>'Ruby193'}resp,data=http.post("/","name1=value1&name2=value2",headers)putsdata对于open-uri我无法执行POST我使用:data=open("http:

ruby - 融合表 : Why do I keep getting a "400 Bad Request" error when trying to update a table style via Ruby's RestClient gem

我正在尝试使用RubygemRestClient为我的一个FusionTables更新样式。这是我的代码:require'rest_client'tableId=''styleId=''key=''table_url="https://www.googleapis.com/fusiontables/v1/tables/#{tableId}/styles/#{styleId}?key=#{key}"update='{"polygonOptions":{"strokeColor":"#ffffff"}}'token='STRINGCONTAININGAUTHORIZATIONTOKEN'R

ruby-on-rails - ruby rails : How to sort a collection_select

我想按数据库表列“plays”对其进行排序/排序(按我想要的方式降序或升序)我完全糊涂了。刚刚找到了select而不是collection_select的解决方案?我的一些代码不知道如何排序/排序数据库表中还有一些列,如“plays”、“goals”... 最佳答案 只需将实际排序的集合传递给collection_select助手:collection_select(:post,:author_id,Author.order('created_atDESC'),:id,:name_with_initial,:prompt=>true

ruby - RubyMine 中的 "Get Available Generators List"警告。我该如何摆脱这个?

我正在使用RubyMine5.4.1并使用ruby​​1.9.3-p0创建一个新的rails3.2.9应用程序,并收到以下警告。我相信bundler当时正在运行install。警告标题为“GetAvailableGeneratorsList”,并发出以下警告,第一个是“Getavailablegeneratorsscriptexecuteswitherrors”:这是在告诉我我必须提供一个“secret”来让future版本的rake正常运行,还是在告诉我提供“secret”只是一个临时修复,但不适用于rake的future版本?如何永久修复此警告,以便我可以接受rake,并处理漏洞?

ruby-on-rails - 如何使用 grouped_collection_select 显示多选?

我正在使用以下代码来显示类别的TreeView选择框:grouped_collection_select(:categories,:category_id,Category.top_level,:children,:name,:id,:name,:include_blank=>true)如何更改它以允许多选?此外,是否可以让它显示复选框而不是选择框? 最佳答案 尝试grouped_collection_select(:categories,:category_id,Category.top_level,:children,:name

ruby-on-rails - Rails 3.2 ActiveAdmin 'Collection is not a paginated scope.' 错误

我正在使用Rails3.2和ActiveAdmin0.4.4开发应用程序。我有一个名为Teaser的模型(/app/models/teaser.rb):classTeasertruemount_uploader:img,TeaserUploaderend然后我向其中添加了ActiveAdmin(/app/admin/teaser.rb):#encoding:UTF-8ActiveAdmin.registerTeaserdoformdo|f|f.inputs"Teaser"dof.input:name,:label=>'Текст'f.input:url,:label=>'Ссылка'

ruby-on-rails - PHP 魔术方法 __call、__get 和 __set 的 Ruby 等价物

我很确定Ruby有这些(等同于__call、__get和__set),否则find_by将如何在Rails中工作?也许有人可以举一个简单的例子来说明如何定义与find_by相同的方法?谢谢 最佳答案 简而言之你可以映射__调用带有参数的method_missing调用__设置为方法名称以'='结尾的method_missing调用__获取不带任何参数的method_missing调用__调用PHPclassMethodTest{publicfunction__call($name,$arguments){echo"Callingob

Ruby:STDIN.gets() 和 gets.chomp() 有什么区别?

Ruby中的STDIN.gets()和gets.chomp()有什么区别?他们不是都从用户那里检索原始输入吗?附带问题:如果我想将他们的输入转换为整数,我该怎么做myNumb=Integer(STDIN.gets())和myNumb=Integer(gets.chomp()) 最佳答案 gets实际上是Kernel#gets.它从作为参数传递的文件中读取,或者如果没有参数,则从标准输入中读取。如果你只想从标准输入读取,那么你应该更明确一点。STDIN.gets$stdin.gets关于转换,我一般用String#to_i.它可以很好