草庐IT

ruby-on-rails - link_to 与 url_for 与 Rails 中的路径

我开始学习RubyonRails,我有一些疑问。我已经看到Railsdocumentation但我完全不明白它们之间的区别:url_forlink_to路径我如何使用/发现我的应用程序的路径?此外,我可以在路径中发送一个参数,例如:有这样的东西吗? 最佳答案 url_for为您提供网站的完整url,例如:www.example.com/my/path将来自url_formy_path_url.link_to为您提供指向特定路径的链接,例如:link_toexample_path,"clickme"会导致clickme您也可以像这样将

ruby - 使用 Octokit.rb 输出 repos URL

我正在尝试使用Octokit.rb列出Github帐户存储库的详细信息,但似乎无法找到关联的URL。首先,我需要做的就是使用OAuth通过GithubAPI进行身份验证,并将详细信息输出到控制台。到目前为止,这是一个基本示例:client=Octokit::Client.new:access_token=>'my_token'client.repos.eachdo|repo|putsrepo.nameputsrepo.description#html_url&clone_urlgohere.end我确定我忽略了一些明显的东西,但是您需要做什么才能找到html_url、clone_url

ruby-on-rails - 我如何在邮件程序之外使用 Devise 的 `confirmation_url`?

我在Rails项目中使用Devise。我想将确认网址传递给第三方。该url由以下DeviseMailerView中的表达式confirmation_url(@resource,confirmation_token:@token)生成:https://github.com/plataformatec/devise/blob/master/app/views/devise/mailer/confirmation_instructions.html.erb我已经grep了Devise的整个源代码,试图找出confirmation_url定义的人或位置,但我找不到任何东西;它只出现在View中

ruby-on-rails - "554 Please activate your Mailgun account. Check your inbox or log in to your control panel to resend the activation email."错误 Ruby on Rails

我正在使用RubyonRails构建网络应用程序。我正在使用Mailgun作为这个应用程序的邮件程序。当我使用Facebook注册时它工作正常但是当我尝试使用电子邮件和密码注册时,我不断收到此错误“554请激活您的Mailgun帐户。检查您的收件箱或登录到您的控制面板以重新发送激活电子邮件。“我已经在mailgun仪表板中将eamil授权给授权收件人。这是我的代码:Registrations_controller.rbclassRegistrationsControllerconfig/environments/development.rbRails.application.confi

ruby-on-rails - 带有 redirect_to 的 Flash 通知在 rails 中被破坏

我已更新到Rails2.3.10、Rack1.2.1,现在我的所有即时消息都没有显示。我发现在重定向期间,通知是这样传递的redirect_to(@user,:notice=>"Sorrytherewasanerror")在我看来闪存哈希是空的!map:ActionController::Flash::FlashHash{}但是您可以在Controller中看到该消息。是什么原因?session{:home_zip=>"94108",:session_id=>"xxx",:flash=>{:notice=>"Sorrytherewasanerror"},:user_credential

ruby - 自定义 to_yaml 和 domain_type

我需要定义用于序列化/反序列化对象的自定义方法。我想做类似下面的事情。classPersondefto_yaml_type"!example.com,2010-11-30/Person"enddefto_yaml"stringrepresentingperson"enddeffrom_yaml(yaml)Person.load_from(yaml)endend声明序列化/反序列化的正确方法是什么? 最佳答案 好的,这就是我想出的classPersondefto_yaml_type"!example.com,2010-11-30/pe

ruby - 是否可以在 Sinatra 中重写基本 URL?

是否可以重写基本URL?例如而不是www.host.com/使用www.host.com/blah/作为一个基本的url等等:get'/'do...end适用于www.host.com/blah/我可以附加到我的所有路线'/blah/..'但任何gem等。也将无法工作。这可以在Rails中轻松完成,我也想在Sinatra中使用它。 最佳答案 我为此使用了Rack中间件rack-rewrite我对此很满意:)useRack::Rewritedorewrite%r{^/\w{2}/utils},'/utils'rewrite%r{^/\

ruby - Heroku,设计 : Getting 'NoMethodError (undefined method ` to_key' for :user:Symbol)'

我不知道它是什么时候发生的,但我收到了这个错误NoMethodError(undefinedmethod'to_key'for:user:Symbol)此行为仅发生在HerokuCedar堆栈上。我使用Devise(1.4.2)通过FacebookonRails3.1.0.rc6和ruby​​1.9.2-p290进行身份验证。它发生在sign_in_and_redirect(:user,authentication.user)行。这是我的方法:defcreateomniauth=request.env['omniauth.auth']authentication=Authenticat

ruby-on-rails - 在 Rails 中使用主机和多个路径字符串创建 URL

我想使用端点和路径或主机和路径创建URL。不幸的是URI.join不允许这样做:pry(main)>URI.join"https://service.com","endpoint","/path"=>#pry(main)>URI.join"https://service.com/endpoint","/path"=>#我想要的是:"https://service.com/endpoint/path"。我怎样才能在Ruby/Rails中做到这一点?编辑:由于URI.join有一些缺点,我很想使用File.join:URI.join("https://service.com",File.j

ruby-on-rails - rails 4 : how to use OR between conditions on find methods

我的问题类似于thisone,但那里的答案都没有解决我的具体问题。我想找到类似这样的对象:conditions={first_name:@searchORlast_name:@search}Stuff.where(conditions)显然,这种语法是无效的,但这是我能想到的展示我想做的事情的最简单的方法。我想在复杂/复合条件下使用更简洁的哈希语法。我知道你可以用像这样的“纯字符串条件”手写出来Stuff.where("first_name=#{@search}ORlast_name=#{@search}")...但这不是我想知道的。更新看起来您可以对这样的数组执行OR:Stuff.w