草庐IT

get_random_id

全部标签

ruby - 使用符号读写 Sinatra 参数,例如参数[:id]

我的表单通过POST接收数据。当我执行putsparams时,我可以看到:{"id"=>"123","id2"=>"456"}现在是命令:putsparams['id']#=>123putsparams[:id]#=>123params['id']='999'putsparams#=>{"id"=>"999","id2"=>"456"}但是当我这样做的时候:params[:id]='888'putsparams我明白了{"id"=>"999","id2"=>"456",:id=>"888"}在IRB中它工作正常:params#=>{"id2"=>"2","id"=>"1"}params

ruby-on-rails - rails : Omniauth - "The parameter app_id is required"

我正在按照这个railscast教程在我的rails项目上为facebook身份验证设置omniauth:http://railscasts.com/episodes/360-facebook-authentication?autoplay=true.我只用了4分钟,到目前为止我所做的就是捆绑gemomniauth-facebook并添加,omniauth.rbOmniAuth.config.logger=Rails.loggerRails.application.config.middleware.useOmniAuth::Builderdoprovider:facebook,ENV

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 - Ruby 中的唯一系统 ID ...?

有没有办法在Ruby中生成唯一的硬件相关标识key...? 最佳答案 在Ruby1.9.2中它是builtin.require'securerandom'putsSecureRandom.uuid#ff97e1e1-22d4-44cf-bf5d-ef1e26444a06 关于ruby-Ruby中的唯一系统ID...?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/5339305/

ruby - 如何在 selenium-webdriver 中获取窗口标题、ID 和名称?

我正在尝试从selenium-webdriver(ruby)实现以下方法get_all_window_idsget_all_window_titlesget_all_window_names我运行了SeleniumIDE并将我的脚本导出到RubyTest::Unit。另存为.rb使用AptanaStudio3打开我的脚本进行编辑初始代码片段如下:require"rubygems"require"selenium-webdriver"require"test/unit"classSwitchToPopup3我不断得到的错误是NoMethodError:undefinedmethod`ge

ruby-on-rails - rails friendly_id 并检查条目是否存在

如何检查friendly_id条目在获取之前就存在?例如:defbook@book=Book.find(params[:book_id])end没关系,但我想先检查friendly_id是否存在,例如:defbookifBook.exists?(params[:book_id])@book=Book.find(params[:book_id])else#404notfoundend 最佳答案 对于friendly_idgem的最新版本,您可以说:Book.friendly.exists?params[:book_id]

ruby-on-rails - Ruby on Rails link_to 内部 ID

我如何使用link_to才能正常转到页面上的特定(html)ID如果我想转到我可以使用的页面上的“whatever_id”ClickHere但我想使用我的link_to"mypage",:controller=>"index"},:id=>"#whatever_id"%>辅助方法。有谁知道如何做到这一点?可能吗?rails2.3.4 最佳答案 link_to可以将anchor添加到URL。来自documentation,link_to"Commentwall",profile_path(@profile,:anchor=>"wall

ruby-on-rails - Friendly_id 不为旧记录创建 slug

我刚刚将Friendly_idgem添加到我的Rails项目中,希望不使用数据库ID并创建一个slug,但我似乎无法为旧记录创建slug。我的模型看起来像这样。classMapping然后我运行Model.find_each(&:save)但它一直吐出nil结果。我试过完全注释掉should_generate_new_friendly_id但没有成功。有人看到我在这里做错了什么吗?编辑我回滚了我的数据库并重写了我的迁移,这似乎已经解决了这个问题。 最佳答案 如果有人发现这个6年前的问题:没有“doandend”block:find_