我的rails网站是我在localhost Ubuntu上开发的,我有一个移动设备.我的网站运行在http:// localhost:3000
现在我想直接通过我的移动浏览器访问它而不通过互联网.
有没有办法通过wifi或其他方式访问它?
我在哪里设置或配置以激活黄瓜/硒测试以运行瘦服务器而不是默认的Webrick服务器?
我有一个条件,我需要传递一个参数作为哈希数组,如下所示:
以下是API调用的Rack :: Test post方法.
post "#{url}.json",
:api_key => application.key,
:data => [{"Company"=>"Apple,Inc","Website"=>"Apple.com"},{"Company"=>"Google","Website"=>"google.com"}],
:run => { :title => "The First Run" }
Run Code Online (Sandbox Code Playgroud)
这是rails应用程序的日志.
Parameters: {"api_key"=>"6a9acb84d0ea625be75e70a1e04d26360606ca5b", "data"=>[{"Company"=>"Apple,Inc", "Website"=>"Apple.com"}, {"Company"=>"Google", "Website"=>"google.com"}], "run"=>{"title"=>"The First Run"}, "line_id"=>"4e018e2c55112729bd00000a"}
Run Code Online (Sandbox Code Playgroud)
现在,这是我用来调用API的RestClient post方法.
RestClient.post("/lines/#{@line.id}/runs.json", {:run => {:title => @title}, @param_for_input => @param_data})
Run Code Online (Sandbox Code Playgroud)
这是rails应用程序的日志.
Parameters: {"run"=>{"title"=>"run name"}, "data"=>{"Company"=>"Google", "Website"=>"google.com"}, "api_key"=>"f488a62d0307e79ec4f1e6131fa220be47e83d44", "line_id"=>"4e018a505511271f82000144"}
Run Code Online (Sandbox Code Playgroud)
不同之处在于data参数.
使用Rack :: Test方法发送时,数据将作为 "data"=>[{"Company"=>"Apple,Inc", "Website"=>"Apple.com"}, {"Company"=>"Google", "Website"=>"google.com"}]
但是通过RestClient方式,参数数据数组被剥离出来,只传递最后一个哈希值 "data"=>{"Company"=>"Google", "Website"=>"google.com"}
为什么RestClient将哈希数组剥离到数组的最后一个哈希?
我使用了以下date_select助手,但没有一个按预期工作.我想要选择默认选项框的空白选项.使用以下所有代码,我得到选择框但选择了当前日期.我在轨道上2.3.2
<%= f.date_select :featured_at, :default => {:day => nil, :month => nil, :year => nil} %>
<%#= date_select("post", "featured_at", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) %>
<%#= date_select("post", "featured_at", :default => { :day => nil }) %>
<%#= f.date_select :featured_at, :include_blank => true, :order => [:day, :month, :year] %>
Run Code Online (Sandbox Code Playgroud) 如何更改以下方法tap来停止警告
DEPRECATION WARNING: Object#returning has been deprecated in favor of Object#tap. (called from full_messages at /Users/millisami/apps/pandahr/config/initializers/fix_active_model_full_message.rb:17)
:
ActiveModel::Errors.class_eval do
# Remove complicated logic
def full_messages
returning full_messages = [] do
self.each_key do |attr|
self[attr].each do |msg|
full_messages << msg if msg
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud) 我正在学习和使用rails构建emberjs应用程序.在这个应用程序中,我希望推送数据而不是轮询到客户端应用程序.
For.eg http://awardwinningfjords.com/2011/12/27/emberjs-collections.html上的以下片段
// Setup a global namespace for our code.
Twitter = Em.Application.create({
// When everything is loaded.
ready: function() {
// Start polling Twitter
setInterval(function() {
Twitter.searchResults.refresh();
}, 2000);
// The default search is empty, let's find some cats.
Twitter.searchResults.set("query", "cats");
// Call the superclass's `ready` method.
this._super();
}
});
Run Code Online (Sandbox Code Playgroud)
它调查twitter API,但我的问题是如何制作一个使用WebSocket连接更新其状态的EmberJS应用程序?
我在Rails3应用程序上添加了一个API,它非常好用.但我在http://developer.github.com/v3/看到了以下Github api v3
HTTP/1.1 422 Unprocessable Entity
Content-Length: 149
{
"message": "Validation Failed",
"errors": [
{
"resource": "Issue",
"field": "title",
"code": "missing_field"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我喜欢错误消息结构.但无法让它重现.我怎样才能让我的apis做出类似的回应?
在为json服务的Rails 3.0.3应用程序构建api时,会发生一些意想不到的行为.
以下是控制器.问题是关于respond_with.我已经respond_to :json在app控制器中了.
create动作正常工作,数据也会在创建后发回.
但更新操作respond_with不会发回任何数据.
响应正文是空白的.
def create
line = get_line
input_header = line.input_headers.create(params[:input_header])
respond_with(input_header, :location => api_v1_line_input_header_url(line,input_header))
end
def show
input_header = get_input_header
respond_with(input_header.to_json)
end
def update
input_header = get_input_header
input_header.update_attributes(params[:input_header])
respond_with(input_header, :location => api_v1_line_input_header_url(input_header.line,input_header))
# render :json => input_header
end
Run Code Online (Sandbox Code Playgroud)
当我使用render :json => input_header而不是respond_with,它的工作原理.为什么是这样?
现在,我正在使用以下配置将我的应用程序域迁移app.example.com到:app.newexample.comnginx
server {
server_name app.example.com;
location /app/ {
rewrite ^/app/(.*)$ http://app.newexample.com/$1;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要显示一个popup-banner来通知用户域名迁移.我希望这个基于referrer或者某种其他标题app.newexample.com
但是我如何在上面附加一个额外的标题,rewrite以便javascript将检测到标题并仅在该标题存在时显示标题因为直接用户app.newexample.com不应该看到弹出横幅?
生成rails 4.2.0 app并添加了activerecord-postgis-adapter并相应地编辑了database.yml文件.
但是现在当我这样做时rake db:create,它会带来错误:
± be rake db:create 2.1.0
rake aborted!
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition
/Users/millisami/Railsapps/showme/config/application.rb:16:in `<top (required)>'
/Users/millisami/Railsapps/showme/Rakefile:4:in `require'
/Users/millisami/Railsapps/showme/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)