我想向rails应用程序发送POST请求,并将其保存并解析数据库中的请求主体...
我在接收端的路由目前设置为:
post '/request' => 'controller#receives_data'
Run Code Online (Sandbox Code Playgroud)
当我将数据发布到此控制器时,我使用:
def post_it
connection.post(uri.path, "this is data", header_with_authkey)
end
Run Code Online (Sandbox Code Playgroud)
接收帖子的我的控制器方法设置为:
def receives_data
log(request.body.read)
end
Run Code Online (Sandbox Code Playgroud)
但是我得到了422 error, unprocessable entity,日志文件总是空的...
是否需要包含特定标头才能将其发布到rails应用程序?我需要在控制器或路由中包含哪些特定配置?
我目前正在开发一个将角度JS集成到Rails应用程序中的教程.
测试设置如下:
describe( 'Club functionality', function() {
// mock Application to allow us to inject our own dependencies
beforeEach(angular.mock.module('league'));
// create the custom mocks on the root scope
beforeEach(angular.mock.inject(function($rootScope, _$httpBackend_, $state){
//create an empty scope
scope = $rootScope.$new();
// we're just declaring the httpBackend here, we're not setting up expectations or when's - they change on each test
scope.httpBackend = _$httpBackend_;
scope.$state = $state;
}));
afterEach(function() {
scope.httpBackend.verifyNoOutstandingExpectation();
scope.httpBackend.verifyNoOutstandingRequest();
});
...
Run Code Online (Sandbox Code Playgroud)
在完成教程的这一部分并浏览一些Angular文档后,我仍然不清楚为什么在包含$ httpBackend依赖项时使用下划线.为什么这样被嘲笑?scope.httpBackend = _$httpBackend_;
我正在编写一个我在rails控制台中运行的脚本.
当我对文件进行更改时,即使我退出并重新加载rails控制台,它也无法识别这些更改.
如何让rails识别并加载对此文件的更改?
该文件位于我的应用程序的根目录中.我加载rails控制台并运行:
require 'file.rb'
Run Code Online (Sandbox Code Playgroud)
该文件将在第一次运行正常,但如果我对文件进行更改,则不会加载它们.我可以删除文件中的所有代码并再次运行该文件,它仍然像编辑前一样运行.
我试图通过Savon gem的源代码工作,我找到了这条线..
def initialize
@documents = []
end
def <<(document)
@documents << document
end
Run Code Online (Sandbox Code Playgroud)
我很好奇该def <<方法的作用.为什么他可能选择使用这种语法而不是更传统的东西(也许).
源代码可以在以下网址找到:https: //github.com/savonrb/savon/blob/master/lib/savon/wsdl/document_collection.rb
我使用ruby 2,rails 4和mongoid-rails gem
我有两个型号:
class Product
embeds_one :feature
end
class Feature
embedded_in :product
field :color, type: String
end
Run Code Online (Sandbox Code Playgroud)
让我们说我有一个产品:
p = Product.new
Run Code Online (Sandbox Code Playgroud)
我想能够打电话给:
p.color = "blue"
Run Code Online (Sandbox Code Playgroud)
而不是必须做:
p.feature.color = "blue"
Run Code Online (Sandbox Code Playgroud)
调用属性也是如此:
p.color
=> "blue"
Run Code Online (Sandbox Code Playgroud)
与不太理想(和目前的情况)
p.feature.color
=> "blue"
Run Code Online (Sandbox Code Playgroud)
我知道有活动记录你可以使用委托,但是如何在mongoid中设置它而不必用大量引用特征模型的方法来填充我的模型?
我有一个模特Author。我想为每个人分配Article一个Author,但不是所有作者都是AdminUser(我的其他模型)。如何设置模型关联,以便每篇文章都必须有一个作者,但并非每个作者都必须具有管理员权限?
如果可以的@article.author话,即使是AdminUser,它也会返回作者
class Author < ActiveRecord::Base
attr_accessor :first_name, :last_name
has_many :articles
end
class AdminUser < ActiveRecord::Base
attr_accessor :first_name, :last_name, #...a bunch of authentication params, passwords, salt, etc
has_many :articles
end
Run Code Online (Sandbox Code Playgroud)
我希望不必再说@ article.admin_user。
我有一个Github Rails项目,我创建了一个模型问题.它有一些错误,所以我将它移出项目文件夹并推送更改.但是,现在当我去推送更改时,文件会神奇地出现在我的存储库中,好像我从未删除它...我该如何解决这个问题?
我有一个像这样的控制器设置:
.controller( 'ProductsCtrl', function ProductsController( $scope, ProductRes, $state, $http ) {
$scope.updateThing = function() {
$scope.thing = true;
};
...
Run Code Online (Sandbox Code Playgroud)
在视图中我有:
<button ng-click='updateThing()'>CLICK THIS TO HIDE THE P</button>
<p ng-hide="{{thing}}">hide this when button clicked</p>
Run Code Online (Sandbox Code Playgroud)
我的其他绑定工作,如输入过滤器和什么不.所以,它告诉我这个特定的设置有问题......