我是绿色的,但有一个关于修改脚手架的基本问题:添加变量的通知。例如,rails 为我创建了以下 create 方法:
def create
@order = Order.new(params[:order])
respond_to do |format|
if @order.save
format.html { redirect_to(@order, :notice => 'Order was successfully created.') }
format.xml { render :xml => @order, :status => :created, :location => @order }
else
format.html { render :action => "new" }
format.xml { render :xml => @order.errors, :status => :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想要做的是向 :notice 添加一个变量,以便它可以具体打印创建的订单(或使用更新方法编辑的订单)。我尝试了一些基本的东西,例如传递<%= order.id %>,尽管我觉得这在控制器中看起来不自然?
在此脚手架的这种格式中是否可以添加动态值?或者它是否违反公约。
感谢您的帮助,对不起,如果这是非常新手。
嘿,我遇到了以下问题。这是jspx文件的内容:
function postSMTH() {
$.ajax({
type: "POST",
url: document.getElementById("urltxt").value,
data: parameters,
});
}
<input type="hidden" value="${pageContext.request.contextPath}/foo/foo2/foodat" name="urltxt" id="urltxt"/>
<div class="foodat"><a href="javascript:postSMTH();"><spring:message code="foo_foo2_foodat_text" text="FOODAT"/></a></div>
Run Code Online (Sandbox Code Playgroud)
因此,如果我按下提交按钮,postSMTH则会调用该函数并将 ajax 对象粘贴到 Controller 中,如下所示:
@Controller
@RequestMapping(value="/foo")
public class FooController {
..............
@RequestMapping(value="/foo2", method=RequestMethod.POST)
public String homePOST(HttpServletRequest request) {
........
}
@RequestMapping(value="/foo2", method=RequestMethod.GET)
public String homeGET(HttpServletRequest request) {
........
}
@RequestMapping(value="/foo2/foodat", method=RequestMethod.POST)
public String doTHAT(HttpServletRequest request) {
// check authorization
Map fooMap = request.getParameterMap();
// do something in the Database, depending on the paramMap
return …Run Code Online (Sandbox Code Playgroud) 在每个页面加载上运行if语句来检查我是否应该运行脚本是不是一个坏主意.例如,我有一个非常长的javascript文件,只需要在使用表单时运行.但是目前在我的每个文件中我都包含了document.addEventListener("turbolinks:load", function()这意味着它会在每个页面加载时运行.
在我的脚本中,我很想在文件的开头写一个if语句,如下所示:
document.addEventListener("turbolinks:load", function() {
controller = $('body').data('controller')
action = $('body').data('action')
if controller == foo && action == bar
runScripts();
else
return;
function runscripts() {
...
Run Code Online (Sandbox Code Playgroud)
我仍然有点使用带有rails的javascript,所以我不知道另一种方式.有什么建议?
背景:
在大型控制器内部,我将调用许多不同的功能,创建用户,更新订单,在事件中安排.这些操作中的每一个都由模型层中的函数处理...以下是其中一个函数的示例:
$user_id = 1;
$data = array('name' => 'Billy');
if (updateUser($user_id, $data) === false) {
// handle error?
}
// continue with rest of controller
Run Code Online (Sandbox Code Playgroud)
问题:
我终于在今天进行了现实检查,并意识到我没有充分的理由像这样编码......
如果updateUser()返回false,那么我的数据库抽象层出现严重问题,导致我无法更新数据库中的数据.这绝不应该发生,因此无论如何都不会向我的用户显示实际错误(这将允许他们采取适当的行动).
基本上我的应用程序从根本上打破了.
题:
我应该懒得检查功能应该不会返回假的?如果是这样的话?或者我应该在没有任何检查的情况下直接打电话给他们
updateUser($foo)
createBooking($bar)
scheduleEvent($qux)
Run Code Online (Sandbox Code Playgroud) 在php artisan route:列表我有
GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest
Run Code Online (Sandbox Code Playgroud)
但是当我去App\Http\Controllers\Auth\LoginController.php时,我所拥有的是以下内容.如何找到'@showLoginForm'部分以便我可以编辑这个控制器?
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/ …Run Code Online (Sandbox Code Playgroud) 这是我的情况,我在Netbeans 8.2中有一个项目,在html中,这里调用angularjs,但是当需要从angular调用java控制器时我们在chrome调试中收到"not found",在工厂用$ http发送"url",但我不能调用java控制器.
- 这是代码html
<div data-ng-app="myApp">
<div data-ng-controller="MyController">
<button data-ng-click="getDataFromServer()">Test Angularjs</button>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
- 这是angularjs中的代码(这是一个File.js)
var app = angular
.module('myApp', ['ngRoute', 'ngResource'])
.controller('MyController', function ($scope, $service, $http, $resource) {
$scope.getDataFromServer = function () {
$service.JS_STST_GetData();
}
})// end controller
.factory(
'$service',
function ($http) {
return {
JS_STST_GetData: function (){
$http({
method: 'POST',
url: 'TestMaping',
headers: {
'Content-Type': 'application/json'
}
}).then(_success, _error);
},
Run Code Online (Sandbox Code Playgroud)
- 这是Java控制器代码
@Controller
public class VerController {
@RequestMapping(value="/TestMaping", method = RequestMethod.POST)
public String TEST(Model model){
return …Run Code Online (Sandbox Code Playgroud) 当我创建新的控制器时,总是抛出错误“ Controller']是名称空间,但使用起来却像类型”。我不知道如何解决它,我已经安装了软件包。在此处输入图片说明
我们正在创建用户的编辑数据页面,因此文本字段已经充满了用户数据,用户可以更改并保存它。问题是,当我开始在文本字段中输入字符时,光标会丢失,每个字符我输入(从设备键盘输入),光标移到第一个字符...并且如果我删除带有初始值的控制器,它可以正常工作,但是我的文本字段无法填充用户数据。
代码示例:
child: StreamBuilder<String>(
stream: _bloc.myStream,
builder: (context, snap) => TextField(
decoration: InputDecoration(
hintText: 'example',
labelText: 'Name',
errorText: snap.error,
),
onChanged: _bloc.updateMyStream,
controller: TextEditingController(text: snap.data),
),
),
Run Code Online (Sandbox Code Playgroud) 当我尝试将此json转换为时间时,出现错误
输出:
这里---------------------------------- 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC
生的:
{
"tenantID": "9e266e1a750e45f8862e83341a5d0970",
"startTime": "2019-4-1T11:45:26.371Z",
"endTime": "2019-4-10T11:45:26.371Z"
}
Run Code Online (Sandbox Code Playgroud)
控制器:
var bodyBytes []byte
raw := make(map[string]interface{})
jsons := make(map[string]interface{})
if h.Ctx.Request.Body != nil {
bodyBytes, _ = ioutil.ReadAll(h.Ctx.Request.Body)
}
json.Unmarshal(bodyBytes, &raw)
time1, err := time.Parse(time.RFC3339,raw["startTime"].(string));
time2, err := time.Parse(time.RFC3339,raw["endTime"].(string));
fmt.Println("HERE------------------------------------",time1,time2)
usageSingle, err := compute.UsageSingleTenant(raw["tenantID"].(string), time1, time2)
Run Code Online (Sandbox Code Playgroud) 我解释我的问题:
我有2个型号:
- User (id, firstname, lastname, deviceid, email, password);
- Message (id, fromuser, touser, description)
Run Code Online (Sandbox Code Playgroud)
我想要外键:
-: fromuser (Message) -> id (User)
-: touser (Message) -> id (User)
Run Code Online (Sandbox Code Playgroud)
在我的模型中:
USER
-> has_many :messages
MESSAGE
-> belongs_to :users
Run Code Online (Sandbox Code Playgroud)
在我的架构迁移中:
create_table "messages", force: :cascade do |t|
t.string "description"
t.integer "fromuser"
t.integer "touser"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "users", force: :cascade do |t|
t.string "firstname"
t.string "lastname"
t.string "deviceid"
t.string "email"
t.string "password" …Run Code Online (Sandbox Code Playgroud) controller ×10
java ×2
ruby ×2
ajax ×1
angularjs ×1
api ×1
asp.net-core ×1
asp.net-mvc ×1
beego ×1
flutter ×1
go ×1
if-statement ×1
javascript ×1
laravel ×1
model ×1
php ×1
redirect ×1
routes ×1
rubygems ×1
scaffolding ×1
spring ×1
textfield ×1