这个问题有点长,因为它是概念性的.我希望这不是一个糟糕的读:)
我正在使用性能关键的Spring MVC/Tiles web-app(10,000个用户典型负载).我们加载更新员工屏幕,我们在其中加载员工详细信息屏幕(绑定到员工业务对象)以通过MultiActionController进行更新.此屏幕上有多个选项卡,但只有tab1具有可更新数据.其余的标签是只读的东西,基本上可供参考.
不用说,我们决定以懒惰的方式加载这些只读选项卡,即,当每个选项卡被激活时,我们触发ajax调用(一次性)以从服务器获取数据.我们不会通过更新视图加载方法加载所有内容.请记住:这是一次只读数据.
现在,我处于两难境地.我已经创建了另一个多路动作控制器,名为"AjaxController"来处理这些ajax调用.现在,我的问题:
思考:如果我让它请求作用域,那么10,000个用户一起可以创建10,000个这个bean的实例:内存问题.如果我将其作为会话范围,那么将为每个用户会话创建一个.这意味着,当10,000个用户登录到应用程序时,无论他们是否使用AjaxController方法,他们都将拥有一个bean.
想法:弹簧靴时会创建一个单独的bean,这个实例将在整个过程中提供.听起来不错.
思考:在这种情况下,是否可以在静态方法上与语境冲突?例如:scope ="session"/"request"+静态方法有意义吗?我问,因为即使每个用户会话都有自己的AjaxController bean,处理程序方法实际上附加到类,而不是实例.另外,scope ="singleton"+静态处理程序方法是否有意义?
想法:如果我控制创作怎么办:基本上做GoF单身.然后范围规范可以做什么?范围会话/请求肯定无法创建多个实例吗?
我糊涂了.我基本上只需要一个控制器bean的单个实例来为所有客户端提供所有请求.
重要说明:AjaxController bean在其他任何地方都不是INJECTED,它是隔离的.它的方法是通过ajax调用命中的.
我正在使用配置文件应用程序做一个简单的用户.用户注册并自动登录.到目前为止工作正常.现在,我想在注册成功后创建个人资料,并将用户重定向到他/她的个人资料.
我有一个用户模型和控制器.Devise还创建了注册控制器.我安装了宝石.我复制了设计文件,我计划覆盖创建操作.
首先,无论我在registrations_controller.rb中编辑什么都没有变化.
class Devise::RegistrationsController < ApplicationController
prepend_before_filter :require_no_authentication, :only =>
[ :new, :create, :cancel ]
prepend_before_filter :authenticate_scope!, :only =>
[:edit, :update, :destroy]
include Devise::Controllers::InternalHelpers
Run Code Online (Sandbox Code Playgroud)
其次,如何插入配置文件创建步骤?
def create
build_resource
if resource.save
if resource.active?
set_flash_message :notice, :signed_up
sign_in_and_redirect(resource_name, resource)
else
set_flash_message :notice, :inactive_signed_up, :reason =>
resource.inactive_message.to_s
expire_session_data_after_sign_in!
redirect_to after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords(resource)
render_with_scope :new
end
end
Run Code Online (Sandbox Code Playgroud)
我想补充一下
current_user.create_profile under is resource.active?
Run Code Online (Sandbox Code Playgroud)
你们怎么解决这个问题?
我在Rails 3上运行了ambethia的reCAPTCHA插件.有谁知道如何覆盖它的flash消息标记?我想重用我自己的flash_errordiv id而不是使用插件的flash_recaptcha_errordiv id:
<div id="flash_recaptcha_error">incorrect-captcha-sol</div>
Run Code Online (Sandbox Code Playgroud)
另外,你如何清理这个控制器#create?
def create
@post = Post.new(params[:post])
respond_to do |format|
if verify_recaptcha(:model => @post, :error => "reCAPTCHA incorrect. Try again.") && @post.save
flash.now[:notice] = "Created \"#{@post.title}\""
format.html { redirect_to(@post, :notice => 'Post was successfully created.') }
else
flash.now[:error] = "Incorrect word verification. Are you sure you\'re human?"
format.html { redirect_to(:back, :error => 'reCAPTCHA incorrect. Try again.') }
end
end
end
Run Code Online (Sandbox Code Playgroud)
感谢您阅读我的问题.
controller ruby-on-rails recaptcha ruby-on-rails-plugins ruby-on-rails-3
我正在使用mvcContrib生成网格,以允许用户通过键入搜索数据来过滤数据。我的索引视图中呈现了几个局部视图:
这是处理搜索的局部视图:
@model CRMNPS.Models.PagedViewModel<CRMNPS.Models.NPSProcessed>
@using (Html.BeginForm("Index", "Home", FormMethod.Get))
{
<label>
Model Number: @Html.TextBox("searchWord" )
<br /><br />From Date: @Html.EditorFor(m => m.FromDate)
</label>
<label>
<Br /><br />To Date: @Html.EditorFor(m => m.ToDate)
</label>
<label>
<br /><br /> <input class="button" value="Search" type="submit" />
<br />
</label>
}
Run Code Online (Sandbox Code Playgroud)
这是我的索引视图:
@model PagedViewModel <CRMNPS.Models.NPSProcessed>
@{
ViewBag.Title = "CRM Processed List";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Processed List</h2>
@{Html.RenderPartial("SearchBox");}
@{Html.RenderPartial("Pager", Model.PagedList);}
@Html.Grid(Model.PagedList).AutoGenerateColumns().Columns(column =>{
column.For(x => Html.ActionQueryLink(x.ModelNumber, "Edit", new { id = x.Id
})).Named("Id").InsertAt(1);
}).Sort(Model.GridSortOptions).Attributes(@class => "grid-style")
@using (Html.BeginForm("Index", "Home", …Run Code Online (Sandbox Code Playgroud) 我想显示被调用的模块,控制器和方法
我以为在cms模块中找到了
应用程序\代码\核心\法师\ CMS \
调用IndexController.php并使用IndexAction方法.因为它是默认页面url.
但是当我试图在IndexAction方法中回应一些东西时.没有出现.我甚至尝试手动调用它,它仍然重定向到主页.
本地主机/ magento的/ index.php的/ CMS /索引/索引/
我做得对吗?如何显示在magento中调用的请求URL?
我一直到处都是(我想)并且似乎找不到在html5音频控制器中调用停止事件的方法.我的音频控制器有一个播放列表,每个音轨在选中时播放,或者循环播放每个音轨到下一个音轨.还有一个下一个按钮可以工作.
我的播放/暂停按钮如下所示:
` function playPause() {
var audioPlayer = document.getElementsByTagName('audio')[0];
if(audioPlayer!=undefined) {
if (audioPlayer.paused) {
audioPlayer.play();
} else {
audioPlayer.pause();
}
} else {
loadPlayer();
}
}
`
Run Code Online (Sandbox Code Playgroud)
我需要一个"停止"按钮来停止音频并返回到当前正在播放的曲目的开头.我想过以某种方式使用当前的播放位置,但无法理解这一点.
我也试过这个(通过另一个问题的建议改编),但无济于事:
` function stop() {
var audioPlayer = document.getElementsByTagName('audio');
addEventListener('loadedmetadata', function() {
this.currentTime = 0;
}, false);
}
`
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我需要将测试应用于特定的控制器.
测试这个控制器是好的:
angular.module('app', []).controller('PasswordController', function PasswordController($scope) {
$scope.password = '';
$scope.grade = function () {
var size = $scope.password.length;
if (size > 8) {
$scope.strength = 'strong';
} else if (size > 3) {
$scope.strength = 'medium';
} else {
$scope.strength = 'weak';
}
};
});
Run Code Online (Sandbox Code Playgroud)
但我想测试一下:
angular.module('app', []).controller('PasswordController', function PasswordController($scope) {
var vm = this;
vm.password = '';
function grade() {
var size = vm.password.length;
if (size > 8) {
vm.strength = 'strong';
} else if (size > 3) …Run Code Online (Sandbox Code Playgroud) 我是MiniTest的新手.大多数测试都很容易掌握,因为它是Ruby代码,并且还具有Rspec风格的可读性.但是,我在身份验证方面遇到了麻烦.与任何应用程序一样,大多数控制器都隐藏在某种身份验证之后,最常见的是authenticate_user确保用户登录.
如何测试session- >用户已登录?我从头开始使用身份验证而不是设计.
我确实将此作为参考:https://github.com/chriskottom/minitest_cookbook_source/blob/master/minishop/test/support/session_helpers.rb
但不太确定如何实现它.
让我们使用它作为示例控制器:
class ProductsController < ApplicationController
before_action :authenticate_user
def index
@products = Product.all
end
def show
@product = Product.find(params[:id])
end
end
Run Code Online (Sandbox Code Playgroud)
在这些基本实例中,我的测试如何?
test "it should GET products index" do
# insert code to check authenticate_user
get :index
assert_response :success
end
test "it should GET products show" do
# insert code to check authenticate_user
get :show
assert_response :success
end
#refactor so logged in only has to be defined once across …Run Code Online (Sandbox Code Playgroud) 我使用angular-ui-router 0.2.18,角度为1.5.x. 我无法解释为什么我的组件$ onInit会触发两次(我不认为它与我的问题有关,但我也在使用webpack).
我的路由:
myModule.config(function ($stateProvider) {
$stateProvider
.state('app.project', {
abstract: true,
url: '/project',
template: '<ui-view/>'
})
.state('app.project.demo', {
url: '/demo',
template: '<my-component></my-component>'
});
});
Run Code Online (Sandbox Code Playgroud)
我的组件的准系统版本:
myModule.component('myComponent', {
template: require('./my-component.html'),
bindings: {},
controller: function () {
this.alert = function () {
console.log("fires");
};
this.$onInit = function () {
this.alert();
};
}
});
Run Code Online (Sandbox Code Playgroud)
在我的应用程序的某个地方,路由更改由触发<a ui-sref="app.project.demo"></a>.
alert单击链接时该函数会触发两次,但重新加载页面时则不会触发.可能控制器在路由更改时加载了两次?
我已经尝试了在这个SO问题上列出的所有内容:打击 - angularjs-执行 - 控制器 - 两次,但没有成功.
真正令我困惑的是,当我重命名我的州名而不改变其他任何东西时,问题就消失了:
'app.project.demos' 作品'app.projects.demo'工作太(改变后'app.project'至'app.projects'当然)可能是什么解释?
路线:
Route::group(['prefix'=>'admin','middleware'=>'auth'],function(){
Route::get('/',['uses'=>'Admin\IndexController@index','as'=>'adminIndex']);
Route::resource('/cat-n-cat','Admin\CatalogsNCategoriesController');
});
Run Code Online (Sandbox Code Playgroud)
控制器:
public function update($data)
{
$category = Category::find($data[0]['id']);
$result = $this->category_rep->updateCategory($data,$category);
if (is_array($result) && !empty($result['error'])) {
return back()->with($result);
}
redirect('admin')->with($result);
}
Run Code Online (Sandbox Code Playgroud)
模型:
public function updateCategory($data,$category){
$data=$data[0];
if (empty($data)) {
return array('error' => 'No data');
}
$result = $this->one($data['name']);
if (isset($result->id) && ($result->id != $category->id)) {
return ['error' => 'Category with this name already exists'];
}
$category->fill($data);
if($category->update()){
return ['status' => 'Category has been added'];
}
}
Run Code Online (Sandbox Code Playgroud)
编辑类重定向后不会触发和我留在同一个页面。如何解决它,为什么它不起作用?