我有以下行动:
def create
binding.pry
@finding.save
respond_with @project, @finding
end
Run Code Online (Sandbox Code Playgroud)
运行以下测试时...
it 'balances the consecutive numbers', focus: true do
expect {
post :create, params: {...}
}.to change { Finding.count }.from(0).to 1
end
Run Code Online (Sandbox Code Playgroud)
...我首先binding.pry显示控制台(证明该#create操作实际已执行),然后规范通过:
Finished in 4.24 seconds (files took 5.31 seconds to load)
1 example, 0 failures
Run Code Online (Sandbox Code Playgroud)
现在当我添加一个expect(controller).to receive(:create)...
it 'balances the consecutive numbers', focus: true do
expect(controller).to receive(:create) # This is new!
expect {
post :create, params: {...}}
}.to change { Finding.count }.from(0).to 1 …Run Code Online (Sandbox Code Playgroud) 我有以下模型(没有 getter 和 setter 以提高可读性):
@Entity
public class Recipe extends BaseEntity {
private String name;
private String description;
private Category category;
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL)
private List<Ingredient> ingredients;
@OneToMany(mappedBy = "recipe", cascade = CascadeType.ALL)
private List<Instruction> instructions;
@ManyToMany
private List<User> administrators;
private int preparationTime;
private int cookTime;
public Recipe(){
super();
ingredients = new ArrayList<>();
instructions = new ArrayList<>();
administrators = new ArrayList<>();
}
public Recipe(String name, String description, Category category, int preparationTime, int cookTime) {
this();
this.name = …Run Code Online (Sandbox Code Playgroud) 这是我的 ViewModel
public class VideoViewModel
{
public string Movie { get; set; }
public int Order { get; set; }
public IList<VideoContent> VideoContents { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何将数据从视图中的字段传递到映射到我的视图模型中的集合的控制器?
在我看来,这段代码正在将 Movie 和 Order 传递给控制器,但我不知道如何发送集合。
@model ViewModels.VideoViewModel
<form method="post">
<div class="form-group">
<label for="movie">Movie</label>
<input type="text" name="Movie" id="movie" class="form-control">
</div>
<div class="form-group">
<label for="order">Order</label>
<input type="text" name="Order" id="order" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Add to database</button>
</form>
Run Code Online (Sandbox Code Playgroud)
提前致谢!
/ 卡勒
我使用 angularjs 从带有复选框的 json 记录中显示表格,我有两个问题:
第一:默认情况下,我需要所有复选框都为真。用 ng-init 测试但不起作用。或者只是一个按钮来切换所有复选框的真假
第二当取消选中文件时,对象显示引号 ["", "", ""],但如果未选中,我需要显示任何内容
看法
<div ng-controller="TestController">
<table class="table table-striped">
<tr>
<th>Seleccionar</th>
<th>Servicio</th>
<th>Detalle</th>
<th>Precio</th>
</tr>
<tr ng-repeat="(key, value) in listado">
<td><input type="checkbox" ng-model="ids[$index]" ng-true-value="{{value}}" ng-false-value="{{ undefined }}" ng-selected="checkAll"></td>
<td>{{ value.modelo }}</td>
<td>{{ value.detalle }}</td>
<td>{{ value.precio_in | currency:'$':0 }}</td>
</tr>
</table>
{{ ids | json }}
Run Code Online (Sandbox Code Playgroud)
控制器
var myApp = angular.module('myApp', [])
.controller('TestController', ['$scope', function ($scope) {
$scope.listado = [];
$scope.ids = [];
$scope.listado = [ { "id_stock": "4", …Run Code Online (Sandbox Code Playgroud) 我在 laravel 5.6 中使用了很多 realtions,当我添加 $phonebooks 时,我看到所有的关系都正常工作,一切都很好,但是当我尝试在视图中显示它们时,我得到此集合中不存在属性的错误这是关系代码
public function client() {
return $this->hasMany('App\Client','id' , 'client_id');
}
Run Code Online (Sandbox Code Playgroud)
这是控制器
public function index()
{ $phonebooks = Phonebook::with('client')->get();
return view('admin.phonebooks.index',compact('phonebooks',$phonebooks));
}
Run Code Online (Sandbox Code Playgroud)
最后这是我如何尝试在视图中展示它们
<tbody>
@foreach($phonebooks as $phonebook)
<tr>
<th scope="row">{{$phonebook->id}}</th>
<th scope="row">{{$phonebook->title}}</th>
<td><a href="/admin/phonebooks/{{$phonebook->id}}">{{$phonebook->description}}</a></td>
<td>{{$phonebook->calldate}}</td>
<td>{{$phonebook->created_at->toFormattedDateString()}}</td>
<td>{{ $phonebook->client->title}}</td>
<td>
<div class="btn-group" role="group" aria-label="Basic example">
<a href="{{ URL::to('admin/phonebooks/' . $phonebook->id . '/edit') }}">
<button type="button" class="btn btn-warning">???????</button>
</a>
<form action="{{url('admin/phonebooks', [$phonebook->id])}}" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="btn btn-danger" …Run Code Online (Sandbox Code Playgroud) 我正在 github 上浏览一些代码:https : //github.com/linnovate/mean/blob/master/server/routes/user.route.js
但有一部分我不明白,那就是:
router.route('/')
.post(asyncHandler(insert));
Run Code Online (Sandbox Code Playgroud)
在 npm express-async-handler 上描述为:
用于处理异步快速路由内的异常并将它们传递给快速错误处理程序的简单中间件。
他们给出了一个如何使用模块的例子,但它没有解释太多。
所以我的问题是:
第12行的insert函数是如何不带括号调用的?
asyncHandler() 的作用是什么,如果你决定不使用它,代码会是什么样子?
通常在使用router.route('/').post 时,后面跟着花括号。在这段代码中,我看不到任何内容。所以我的问题是:异步函数插入router.route('/').post的函数体的一部分吗?如果没有,那么为什么没有花括号?
在第 14 行的user.controller.js 中到底导出了什么(它是一个对象,还是一个 var...)?这样导出有什么好处?为什么不直接导出函数 insert()?
先感谢您。
我想创建特定的 API 路由,该路由将仅用于 WebSocket ( /api/events) 但在 Nest.js 上实现 WebSockets 的所有示例中,我偶然发现模块被导入AppModule并且客户端正在向根 URL 发出事件,我不能这样做是因为我有这个中间件;
前端.middleware.ts
import { Request, Response } from 'express';
import { AppModule } from '../../app.module';
export function FrontendMiddleware(
req: Request,
res: Response,
next: Function,
) {
const { baseUrl } = req;
if (baseUrl.indexOf('/api') === 0) {
next();
} else {
res.sendFile('index.html', { root: AppModule.getStaticAssetsRootPath() });
}
}
Run Code Online (Sandbox Code Playgroud)
这是EventGateway和EventModule:
event.gateway.ts
import {
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
WsResponse,
} from '@nestjs/websockets';
import { …Run Code Online (Sandbox Code Playgroud) 大家好,我正在将 SpringBoot 与 Mysql 一起使用。当我尝试显示信息时出现此错误
我的控制器中有以下代码:
query did not return a unique result: 2; nested exception is javax.persistence.NonUniqueResultException: query did not return a unique result: 2
org.springframework.dao.IncorrectResultSizeDataAccessException: query did not return a unique result: 2; nested exception is javax.persistence.NonUniqueResultException: query did not return a unique result: 2
Run Code Online (Sandbox Code Playgroud)
代码
@GetMapping("showdeveforma/{id}")
public String ShowDeveFormation(Model m , @PathVariable Long id)
{
Formation frm = frmreop.findById(id).get();
m.addAttribute("avis", srv.findByforma(frm));
return"ChefProjetAffichageAffectationDeveForma";
}
Run Code Online (Sandbox Code Playgroud) 我已经安装了 TYPO3 版本。10.我有一个在TYPO3版本上完美运行的自定义扩展。9.我希望这个定制的扩展兼容最新的TYPO3版本。10.但是我安装后报错。下面提到的是错误:
[Semantical Error] The annotation "@inject" in property ABC\EXTSocial\Controller\SocialController::$socialRepository was never imported. Did you maybe forget to add a "use" statement for this annotation?
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?
我有一个围绕 JavaFXML 和 scenebuilder 构建的简单的两个选项卡应用程序。选项卡目前什么都不做,因为我在尝试加载它们时无法通过空指针异常。
java 和 fxml 文件在 Netbeans 项目中排列如下:
Main Application:应用程序主类MainApp.java设置场景,声明如下:
package tabpane;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class MainApp extends Application {
private static Stage primaryStage;
private AnchorPane rootLayout;
public MainApp() {}
@Override
public void start(Stage primaryStage) {
primaryStage.initStyle(StageStyle.UNDECORATED);
MainApp.primaryStage = primaryStage;
MainApp.primaryStage.setTitle("Account Names");
initRootLayout();
}
public void initRootLayout() {
try {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/MainView.fxml"));
rootLayout = …Run Code Online (Sandbox Code Playgroud) controller ×10
spring-boot ×2
view ×2
angularjs ×1
annotations ×1
asp.net ×1
asp.net-core ×1
async-await ×1
checkbox ×1
fxml ×1
hibernate ×1
java ×1
javafx ×1
javascript ×1
laravel ×1
list ×1
mocking ×1
mysql ×1
nestjs ×1
node.js ×1
php ×1
post ×1
repository ×1
routes ×1
rspec ×1
spring ×1
thymeleaf ×1
typo3 ×1
typo3-10.x ×1
viewmodel ×1
websocket ×1