我们都知道IPv4的地址localhost是127.0.0.1(环回地址).什么是IPv6地址localhost和0.0.0.0我需要阻止一些广告主机.
>> string = '#{var}'
=> "\#{var}"
>> proc = Proc.new { |var| string }
=> #<Proc:0xb717a8c4@(pry):6>
>> proc.call(123)
=> "\#{var}"
Run Code Online (Sandbox Code Playgroud)
不是我想要的.双引号string导致显而易见的结果undefined local variable.
我正在尝试使用Ruby on Rails与Salesforce API进行通信.我可以轻松地获取数据,但我在向服务器发布数据时遇到问题.我按照Quinton Wall的帖子使用HTTParty:
但我似乎能够从salesforce服务器获得的是我以html身份提交正文的错误
{"message"=>"此资源不支持'application/x-www-form-urlencoded'的MediaType","errorCode"=>"UNSUPPORTED_MEDIA_TYPE"}
负责的代码如下:
require 'rubygems'
require 'httparty'
class Accounts
include HTTParty
format :json
...[set headers and root_url etc]
def self.save
Accounts.set_headers
response = (post(Accounts.root_url+"/sobjects/Account/", :body => {:name => "graham"}.to_json))
end
end
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么身体应该被发布为html以及如何改变这一点,以便它肯定像json一样,以便salesforce不拒绝它?
任何帮助,将不胜感激.干杯
我的config/locales/pl.yml档案(从这里采样):
pl:
date:
day_names: [Niedziela, Poniedzia?ek, Wtorek, ?roda, Czwartek, Pi?tek, Sobota]
month_names: [~, Stycze?, Luty, Marzec, Kwiecie?, Maj, Czerwiec, Lipiec, Sierpie?, Wrzesie?, Pa?dziernik, Listopad, Grudzie?]
Run Code Online (Sandbox Code Playgroud)
在script/console:
I18n.locale = 'pl'
=> "pl"
Time.now.strftime("%A, %B")
=> "Tuesday, August"
Run Code Online (Sandbox Code Playgroud)
为什么?换句话说 - 我怎样才能获得翻译的月份名称?我还会注意到locale文件肯定是读取的,因为它包含了许多其他翻译,这些都可以工作.
给定以下资源定义:
map.resources :posts, :except => [:show]
map.post '/:year/:month/:slug, :controller => :posts, :action => :show
Run Code Online (Sandbox Code Playgroud)
我可以url_for使用以下语法为我工作:
<%= link_to @post.title, post_url(:year => '2010', :month => '02', :slug => 'test') %>
Run Code Online (Sandbox Code Playgroud)
但有没有办法让这项工作?
<%= link_to @post.title, @post %>
Run Code Online (Sandbox Code Playgroud)
目前它抛出此错误:
No route matches {:year=>#<Post id: 1, title: "test", (...)>, :controller=>"posts", :action=>"show"}
Run Code Online (Sandbox Code Playgroud)
显然它将@post对象传递给第一个路由参数(看起来像是一个Rails错误...).但我可以为我做这项工作吗?我要补充一点,搞乱default_url_options是一个死胡同.
仅在Rails 3.x中工作的解决方案是可以的,但我不想使用任何插件.
有一个宝石,它附加一个before_filter到Rails应用程序:
class Railtie < Rails::Railtie
initializer "..." do
ActiveSupport.on_load(:action_controller) do
ActionController::Base.send(:include, Filter)
...
module Filter
extend ActiveSupport::Concern
included do
append_before_filter :set_locale
end
def set_locale
....
Run Code Online (Sandbox Code Playgroud)
这里是应用程序中的一些控制器:
class DesktopsController < ApplicationController
before_filter :set_language_in_session
Run Code Online (Sandbox Code Playgroud)
现在问题在于,before_filter来自gems的是在before_filter来自DesktopsController 之前的过滤器链中:
DesktopsController._process_action_callbacks.select { |c| c.kind == :before }.collect { |filter| filter.filter }
=> [
[0] :set_locale,
[1] :set_language_in_session
]
Run Code Online (Sandbox Code Playgroud)
我怎样才能使before_filter从宝石(set_locale)放后所有其他过滤器?秘密可能在于这一行:
ActiveSupport.on_load(:action_controller) do
Run Code Online (Sandbox Code Playgroud)
但我尝试了不同的图书馆,没有任何运气......
顺便说一句.这是宝石的完整代码.Ruby 1.9.2,Rails 3.0.5.
Rails 2.3.*,mod_passenger 2.2.*和Apache 2.2.*.是否值得安装mod_pagespeed或Rails是否正确创建所有缓存头等,以便不需要mod_pagespeed?
我正在尝试遵循本手册,其中包含以下说明:
restart taskgated service by killing the current running taskgated process
Run Code Online (Sandbox Code Playgroud)
怎么做?我试图找到taskgated并只得到一些ttys007,但没有任务门控过程:
$ ps | grep taskgated
66942 ttys007 0:00.00 grep --exclude-dir=.svn taskgated
$lsof | grep taskgated
$
Run Code Online (Sandbox Code Playgroud) 生产 Rails 应用程序中最喜欢的日志级别是什么?我刚刚在文档中读到日志记录对生产的影响很小。目前我的日志级别设置为info.
我希望我的网站网址看起来像这样:
example.com/2010/02/my-first-post
Run Code Online (Sandbox Code Playgroud)
我的Post模型有slug字段('my-first-post')和published_on字段(我们将从中扣除网址中的年份和月份).
我希望我的Post模型是RESTful,所以url_for(@post)像他们应该的工作,即:它应该生成上述url.
有没有办法做到这一点?我知道你需要覆盖to_param并map.resources :posts使用:requirements选项集,但我无法全部工作.
我几乎完成了,我90%在那里.使用resource_hacks插件我可以实现这个目的:
map.resources :posts, :member_path => '/:year/:month/:slug',
:member_path_requirements => {:year => /[\d]{4}/, :month => /[\d]{2}/, :slug => /[a-z0-9\-]+/}
rake routes
(...)
post GET /:year/:month/:slug(.:format) {:controller=>"posts", :action=>"show"}
Run Code Online (Sandbox Code Playgroud)
并在视图中:
<%= link_to 'post', post_path(:slug => @post.slug, :year => '2010', :month => '02') %>
Run Code Online (Sandbox Code Playgroud)
生成适当的example.com/2010/02/my-first-post链接.
我也想这样做:
<%= link_to 'post', post_path(@post) %>
Run Code Online (Sandbox Code Playgroud)
但它需要覆盖to_param模型中的方法.应该相当容易,除了事实,to_param必须返回String,而不是Hash …