我正在Rails中建立一个具有特定销售模型的商店.我需要允许用户每30天只向其订单添加3个项目.30天计数器应该在添加第一个order_item时开始.一旦30天到期,用户将能够添加3个订单.如果30天没有通过,例如,用户添加了两个order_items,他仍然可以在30天内再添加一个order_item.因此,如果用户尝试添加超过3个项目以显示错误消息,并忽略将order_items保存到current_user的订单.
我有产品,订单,order_items,用户.我想我应该向用户模型添加一些内容,但我不确定是什么.
order_items_controller.rb
def create
@order = current_order
@order_item = @order.order_items.new(order_item_params)
@order.user_id = current_user.id
@order.save
session[:order_id] = @order.id
respond_to do |format|
format.js { flash[:notice] = "ORDER HAS BEEN CREATED." }
end
end
private
def order_item_params
params.require(:order_item).permit(:quantity, :product_id, :user_id)
end
end
Run Code Online (Sandbox Code Playgroud)
user.rb
class User < ActiveRecord::Base
has_many :identities, dependent: :destroy
has_many :order
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :omniauthable, :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable
end
Run Code Online (Sandbox Code Playgroud)
order_item.rb
class OrderItem < ActiveRecord::Base
belongs_to …Run Code Online (Sandbox Code Playgroud) 尝试从C#迁移到F#(我第一次使用MVC而不是MVVM,所以我的术语可能已关闭),但最终我无法设置我的WPF\XAML DataContext,因此我可以绑定我的UI.
我有以下简单的WPF:
<UserControl x:Class="epic.Sandbox.Controls.FieldController"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:epic.Sandbox.Controls"
xmlns:Views="clr-namespace:epic.View;assembly=epic.Core"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<Views:TextFieldModel />
</UserControl.DataContext>
<Grid>
</Grid>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
和以下F#:
namespace epic.View
open System
open FSharp.Desktop.UI
[<AbstractClass>]
type public FieldModelBase() =
inherit Model()
let mutable fieldCaption: string = null
let mutable fieldValue: System.Object = null
[<DerivedProperty>]
member this.Caption with public get() = sprintf "%s" fieldCaption and set value = fieldCaption <- sprintf "%s" value; this.NotifyPropertyChanged "Caption"
[<DerivedProperty>]
member this.Value with public get() = fieldValue and set value = …Run Code Online (Sandbox Code Playgroud) 我使用Swing开发桌面应用程序时遇到的最大问题是我在完成应用程序时产生的意大利面条.
我来自MVC的PHP背景,我有一种简单的方法来实现依赖注入,当我需要时,我只能访问模型层中的任何地方,我只是构建了所需的类.
但是在Java中对我来说有点复杂,因为Swing组件基本上都是做事情的小模型,问题是,我如何处理它以提供一个漂亮的非意大利面设计.
我称之为意大利面设计?
对我来说,意大利面条设计是我有时会达到这样的程度,在我的组件中,我需要访问另一个组件,或者我需要访问我没有构建的某个地方.为此,我需要将这些实例从组件传递给组件,这意味着我为那些永远不会使用它的组件创建了这些对象的访问权限,并且只是在中间用作传递实例的人.基本上是我问自己的一点.
让我们看看这个虚拟的例子:
你有这个组件Map.该组件应该为您绘制您所在国家/地区的地图,并绘制实体(实体可以只是某个城市标签,军事基地,雷达目标数据以及地图可以显示的任何内容).因此,在您的模型层中,您可能在某处定义了一个名为的类EntitiyManager,其中包含实体列表,每个实体都是继承的MapEntity.那么为了绘制这些实体你需要做些什么呢?
方法1
通过EntityManager对Map和检索数据EntityManager得出:
public class Map extends JPanel {
/**
* Entity manager used to store and manipulate entities
*/
private EntityManager manager;
public Map(EntityManager manager) {
this.manager = manager;
}
// SOME CODE HERE ALOT OF CODE
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
for (Entity e : manager.getEntities()) {
if (!e.isVisible()) {
continue; …Run Code Online (Sandbox Code Playgroud) 我正在使用这种结构的MVC应用程序:
Request
V
FrontController <-> Router
V
Controller <-> Model
V
View
Run Code Online (Sandbox Code Playgroud)
我还需要在此结构中放置另外两个组件:
Authentification:使用$_SESSION全局变量记录用户;RBAC:基于角色的访问控制,可以检查角色是否具有授予"ressource"(Controller方法)的访问权限.每个用户都可以拥有任意数量的角色(他们也可以没有角色).
现在,我需要将这两个组件放在我的应用程序中,我需要它们能够:
User未进行authed并且Request需要User执行authed ,则应将客户端重定向到登录页面;RBAC看到authed User没有一个角色具有授予执行方法所需的"ressource"访问权限的角色,那么仍然应该执行该Controller方法,Controller但知道该方法User没有这样做的权限(示例:A User撰写文章但没有权利发布它,因此文章将保存为草稿,并User告知Moderator必须发布它).我已经有一些想法可以找到它Authentification,RBAC但我不确定:
Authentification可以进入FrontController或者Router;RBAC可以进入FrontController或Controller.我看到有人把它RBAC放在模型中,但我不明白为什么.
我想对这个问题有一些见解.我应该在哪里放置Authentification和 …
对于性能监视器,我实现了在Java中的MVC和决定我的模型分割成单独的类,现在我选它的属性和功能集成到之间徘徊Client,Server和Connection模型类或Benchmark,Logging和Specs模型类.
以前的模型将匹配现实生活中的对象作为"对象",因为它们是应用程序将监视的独立实体.由于MVC如何与观察者一起工作,我的控制器的基准测试功能将触发我所有模型中的更新.
后者通过使模型更多地匹配功能(需求)来解决这种广泛的更新,因此只更新需要更新的模型,仅触发需要修改的视图更新.我认为这种方法会降低我的模型的可重用性.
从几天以来,我一直在努力实现从ASP MVC到Symfony REST世界的模型绑定机制的实现,但是没有运气。
我遇到了类似的东西-@ParamConverter,但是通过尝试,我使它看起来像不是我要找的东西。
我的尝试在Body Converter结束。当我将表单数据发布到所需的路由时:/api/posts我收到有关不存在的路由的错误。调试:路由器给我的路线不同,我预计: /api/posts/{post}.{_format}。在我看来,Body转换器希望我以json或xml格式发送数据,但是由于文件的缘故,我希望发送表格数据。我正在寻找的解决方案应该像这样工作:
/**
* @ParamConverter("Post", class="BlogBundle:Post")
*/
public function postPostAction(Post $post)
{
if($post->isValid())
{
$em->persist($post);
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以提供一些线索,或者实现如何使其工作吗?因为我相信我不仅是一个想要达到这种优雅方式的人
在这段代码中我添加了编程VC:
@IBAction func addPerson(_ sender: UIBarButtonItem) {
let controller = CNContactPickerViewController()
controller.delegate = self
navigationController?.present(controller, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
我点击联系人时使用另一个VC(将信息显示在单元格中,然后我想在我的第一个VC中显示电话/电子邮件的复选框)
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact) {
let vc = EditContactViewController()
self.navigationController?.pushViewController(vc, animated: true)
Run Code Online (Sandbox Code Playgroud)
我为下一个单元格创建了一个类,当我在tableView cellForRowAtIndexPath中执行此操作时,我在storyboard中将标识符设置为单元格
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? ConfigCell
return cell!
Run Code Online (Sandbox Code Playgroud)
这给了我:
fatal error: unexpectedly found nil while unwrapping an Optional value
Run Code Online (Sandbox Code Playgroud)
我也试过withIdentifier,forIndexPath,它说:
2016-11-12 01:35:28.626 iEvents3 [2637:47714]***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使用标识符单元格对单元格出列 - 必须为该单元格注册一个nib或类标识符或连接故事板中的原型单元格'
我删除了重用标识符并将其重新放回,清理了应用程序,重启,一切.
感谢您的时间!
如果有任何方法我可以调试我的nopCommerce插件,我正在寻找机会.我正在研究nopCommerce上的大型销售产品,因此我处于如此危急的境地,无法进行实时测试或调试.因为我无法找到异常的来源.有没有可用的工艺或套件?
提前致谢.
我有一个'事务'模型,控制器和视图,我用rails generate创建.现在我需要向我的应用程序添加一个/ transactions/history的自定义路由,由控制器def历史记录处理:... end和render history.html.erb
所以在我的routes.rb中添加了这一行:
get '/transactions/history', to: 'transactions#history', as: 'transactions_history'
Run Code Online (Sandbox Code Playgroud)
这在我的transactions_controller.rb中:
def history
@transactions = Transaction.all
end
Run Code Online (Sandbox Code Playgroud)
并在transactions-> views中创建了history.htmk.erb
调用rake路由时我也看到这一行:
transactions_history GET /transactions/history(.:format) transactions#history
Run Code Online (Sandbox Code Playgroud)
但是当我在浏览器中请求localhost:3000/transactions/history时,它会给我以下错误:
Couldn't find Transaction with 'id'=history
Run Code Online (Sandbox Code Playgroud)
(因为我的控制器中有这一行)
before_action :set_transaction, only: [:show, :edit, :update, :destroy])
Run Code Online (Sandbox Code Playgroud)
我也在日志中看到这一行:
Request info
Request parameters
{"controller"=>"transactions", "action"=>"show", "id"=>"history"}
Run Code Online (Sandbox Code Playgroud)
我有两个类A和B正在实施的接口.
public class A implements MyInterface {
// Class A stuff
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class B implements MyInterface {
//Class B stuff
private MyCustomClass myCustomclass;
public String getName() {
this.myCustomclass.getName();
}
}
public interface MyInterface {
public String getName();
}
Run Code Online (Sandbox Code Playgroud)
我想使用单个控制器方法,它可以在A和B上工作,具体取决于前端发送的对象.所以当我尝试使用Interface时,Spring抱怨找不到合适的消息转换器.
Run Code Online (Sandbox Code Playgroud)@RequestMapping(value = "/mymethod", method = RequestMethod.POST) public String updateRecord(@RequestBody MyInterface myInterface, HttpServletResponse response) { //Do stuff }