我想发现缺少BDD:包括ActiveRecord :: Base.find方法的参数.所以我的想法是在规范中有这样的东西:
ActiveRecord::Base.should_receive(:find).once.and_proxy_to_original_method
parent = SomeClass.find 34
parent.child.should be_loaded
parent.other_children.should be_loaded
Run Code Online (Sandbox Code Playgroud)
如果没有急切加载#child或#other_children关联,那么期望应该会失败,例如:"预期的ActiveRecord :: Base.find被调用一次但是它被调用了2次以下args:1. ...; 2. ......"
有谁知道是否有一些像这样工作的匹配器或如何制作它.
谢谢
首先加载全局应用程序控制器时,在该名称空间中加载页面时,不会加载命名空间的应用程序控制器.应用程序控制器如下所示:
class ApplicationController < ActionController::Base
protect_from_forgery
end
Run Code Online (Sandbox Code Playgroud)
命名空间的应用程序控制器如下所示:
class Admin::ApplicationController < ApplicationController
def authenticate_admin!
if current_admin.nil?
redirect_to new_admin_session_url
end
end
private
def current_admin
@current_admin ||= Admin.find(session[:admin_id]) if session[:admin_id]
end
helper_method :current_admin
end
Run Code Online (Sandbox Code Playgroud)
当我们使用before_filter"authenticate_admin!"时 像这样:
class Admin::AssetsController < Admin::ApplicationController
before_filter :authenticate_admin!
end
Run Code Online (Sandbox Code Playgroud)
抛出"Admin :: AssetsController #new中的NoMethodError".仅当我们在命名空间路由之前命中全局路由时才会发生这种情况.如果服务器重新启动并且加载了命名空间路由,则一切正常.
ruby ruby-on-rails controllers nomethoderror ruby-on-rails-3.2
我正在尝试将变量从一个视图传递到控制器到另一个视图.我没有得到任何错误,但是当它到达最后一个视图时,它不会显示它应该的变量.在第一个视图中,我只是得到一个名字.
{{ Form::open(array('route' => 'form', 'method'=>'post')) }}
{{ $name = Form::text('name') }}
{{ Form::submit('Go!') }}
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)
这是我的HomeController.php.
public function view1()
{
return View::make('stuff');
}
public function postView1($name)
{
return Redirect::route('view2')->with($name);
}
public function view2($name)
{
return View::make('view2')->with($name);
}
Run Code Online (Sandbox Code Playgroud)
routes.php文件
Route::get('/', array('as' => 'stuff', 'uses' => 'HomeController@stuff'));
Route::post('form/{name}', array('as' => 'form', 'uses'=>'HomeController@postView1'));
Route::get('view2/{name}', array('as' => 'view2', 'uses' => 'HomeController@view2'));
Run Code Online (Sandbox Code Playgroud)
view2.blade.php
{{ $name = Input::get('name') }}
<p> Hello, {{ $name }} </p>
Run Code Online (Sandbox Code Playgroud)
那为什么不出现呢?
我在rails应用程序中使用ActiveAdmin gem.如果我想在适用于所有activeadmin gems的过滤器之前添加一个新的过滤器,我该怎么做?我想我可以在ActiveAdmin中修改BaseController来实现这一点,但是在rails应用程序中进行这种修改的正确方法是什么?有没有办法复制和覆盖BaseController?
作为MVC4 + Entity + WebAPI的新手,我很沮丧,为了简单地将GET,POST控制器处理程序和自定义映射到数据模型.
我想我要问的是有一个生成工具,例如从你的数据类中创建你的控制器类,所以我可以直接从数据中做简单的GET命令?
制作通用RESTful API的方法是什么,因此命令可以这样做
GET api/1.0/{genericdatatype}/{id}
通用数据类型可以是任何模型,没有特定的控制器?说我不需要PUT(通过MVC应用处理)所以我真的不需要POST验证等.
我很抱歉如果我不能很好地解释自己,那么就这样了.基本上我在尝试解决这个问题时遇到了麻烦.我正在使用Yeoman来生成我的角度项目.我有页眉和页脚,页脚将是静态的,页眉将需要自己的控制器.我遇到的问题是,我并不特别希望标题位于其他控制器之外.也许我错了,这实际上并不是一个问题,最好的做法显然是将标题放在外面ng-view?这是我到目前为止:
<head>
<!-- head stuff here -->
</head>
<body ng-app="dscover.me">
<div ng-include src="'partials/header.html'"></div>
<div ng-view="">
</div>
<div ng-include src="'partials/footer.html'"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
这是在页面和页脚之外包含页眉和页脚的正确方法MainCtrl吗?这对我来说只是因为,如果我要创建一个新的控制器/页面,我仍然可以访问它外面的控制器吗?问题再次是我想克制自己使用rootScope,不幸的是,这似乎是唯一的方法,在标题之外MainCtrl?
对于可怕的解释我很抱歉,但我希望你们明白.如果有更好的方法,请告诉我.任何帮助将不胜感激!
考虑一个我有Orders模型的例子.触发index操作会显示系统中的所有订单.
现在我想要一个单独的页面显示所有已退款订单的图表,另一个页面显示所有已取消的订单 - 不仅现在有一个过滤器,而且还有一个全新的视图.
什么是最佳做法:
1.)OrdersController为每个报告创建新的操作(例如,refund_report和cancelled_report)
2.)通过单个操作为每个报告创建新的控制器(例如RefundReportController,CancellationReportController)show?
3)为所有人创造一个报告新的控制器(例如,OrderReportsController)和每个报告的动作(例如refunds,cancellations等等.
或者还有另一种我完全不知道的范例?
我尝试在控制器文件中使用binding.pry,当我重新加载页面时,乘客卡在上面但是irb不起作用(它显示,但卡住了.看起来乘客写了字符串,就是全部.).在乘客网站上我们可以看到,irb是用于商业计划但是如果我们使用binding.remote_pry(binding.pry被rails 3忽略),它的效果很好.当然binding.pry对WEBrick很有用.问题是,如果我是正确的,或者可以将binding.pry与乘客一起使用,但我必须在某处写一些东西以使其有效?
本主题的第二个目标是将链接放在上面,这对于下一个初学者来说.我花了很多时间来找到答案,为什么它不起作用以及如何使其发挥作用.
顺便说一下 - 我们是否还能以某种方式调试/实时调试控制器/视图?我找到了这个,但没试过.
我用的是铁轨4.
我有一个Spring启动应用程序,我想导入一个用spring boot编写的依赖项,它定义了一些控制器.
也许它很简单,但是如何让主应用程序能够在导入的模块中初始化所有这些控制器?当我尝试访问这些控制器的路径时,我得到一个错误,错过了给定路径的处理程序方法.我尝试如下:
@SpringBootApplication
@ComponentScan(basePackages = {"com.main.project", "com.imported.dependency"})
public class MyApplication
implements CommandLineRunner {
public static void main(final String... args) {
SpringApplication app = new SpringApplication(MyApplication.class);
app.setWebEnvironment(true);
app.run(args);
}
}
Run Code Online (Sandbox Code Playgroud)
即我试过@ComponentScan,但没有任何反应.
我还试图查看控制器是否已加载:
ApplicationContext ctx = SpringApplication.run(FrontendApplication.class, args);
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println(beanName);
}
Run Code Online (Sandbox Code Playgroud)
他们不是.我试图删除@SpringBootApplication,并使用@EnableAutoConfiguration和@ComponentScan,但这不起作用.
建议?
我正在尝试将控制器添加到我的Angularjs应用程序中.
这是我第一次在不使用$scope依赖项的情况下进行设置,并使用路由来声明我正在使用的控制器.
在PokemonCtrl没有注册的地方,我做错了什么?另外,如果我在路由中声明控制器这意味着我不必在其他任何地方声明它?
app.js
'use strict';
/**
* @ngdoc overview
* @name pokedexApp
* @description
* # pokedexApp
*
* Main module of the application.
*/
angular
.module('pokedexApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch'
])
.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl',
controllerAs: 'main'
})
.when('/pokemon', {
templateUrl: 'views/pokemon.html',
controller: 'PokemonCtrl',
controllerAs: 'controller'
})
.otherwise({
redirectTo: '/main'
});
});
Run Code Online (Sandbox Code Playgroud)
pokemonCtrl.js
'use strict';
var pokedexApp = angular.module('pokedexApp', []);
pokedexApp.controller('PokemonCtrl', function() {
var vm = …Run Code Online (Sandbox Code Playgroud) controllers ×10
angularjs ×2
activeadmin ×1
asp.net-mvc ×1
bdd ×1
c# ×1
debugging ×1
entity ×1
html ×1
java ×1
javascript ×1
laravel ×1
partials ×1
passenger ×1
php ×1
pry ×1
rspec ×1
ruby ×1
spring ×1
spring-mvc ×1
variables ×1
views ×1
yeoman ×1