这是我目前的代码:
<%= f.collection_select :category_id, Category.all, :id, :name, {prompt: "Choose a category"} %>
<%= f.collection_select :subcategory_id, Subcategory.all, :id, :name, {prompt: "Choose a subcategory"} %>
Run Code Online (Sandbox Code Playgroud)
它只是在一个下拉列表中显示所有类别,在另一个下拉列表中显示所有子类别.像这样
问题:如何根据所选的主要类别显示特定的子类别.使用上面的代码,它显示所有类别和所有子类别.
一切都在模型中链接,has_many和belongs_to ...和category_id和subcategory_id..everything正常工作,我只是不知道如何在所选类别中显示特定的子类别.
我的尝试:
<% if (Category.where(:name=>"Intro")) do |d| %>
<% d.subcategories.each do |subcategory| %>
<%= link_to subcategory.name, gigs_path(subcategory: subcategory.name) %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
此代码出错.我要说,例如,如果用户选择名为"简介"的类别而不是列出所有"简介子类别".但它没有成功 - 我的代码显然是错误的.
谢谢.
我有像下面的MVC代码.我使用nInject for IoC.我想知道当我推送请求时,例如SendMail有创建控制器对象,nInject为两个只读对象创建子对象:_mailSrv和_dbSrv,但我在这个请求中只需要一个变量.
是否可以将变量注入延迟加载.当代码需要对象时,它会被创建吗?
public class HomeController:Controller
{
private readonly IMailService _mailSrv;
private readonly IDatabaseService _dbSrv;
public HomeController:Controller(IMailService mailSrv, IDatabaseService dbSrv)
{
_mailSrv = mailSrv;
_dbSrv = dbSrv;
}
public ActionResult SendMail(string mailAddress)
{
_mailSrv.Do(mailAddress);
}
public ActionResult SaveToDatabase(int id, string data)
{
_dbSrv.Do(id, data);
}
}
Run Code Online (Sandbox Code Playgroud) 我在控制器中有一个按照我想要的方式操作数据的功能.现在我想在index.php文件中调用该函数view.我怎么做?
在我的控制器中
function actionTesting($params){
.....
}
Run Code Online (Sandbox Code Playgroud)
如何在视图中调用它...
<?php
echo $this->testing($params);//Calling unknown method: yii\web\View::testing()
?>
Run Code Online (Sandbox Code Playgroud) 我正在尝试本教程
http://httpjunkie.com/2013/311/adding-mvc-5-identity-to-an-existing-project/
但显示错误错误5名称'ConfigureAuth'不存在在当前上下文中,
这是我的startup.cs类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartupAttribute(typeof(TicketSystem.Startup))]
namespace TicketSystem
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是Startup.Auth.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Owin;
namespace TicketSystem.App_Start
{
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Enable the …Run Code Online (Sandbox Code Playgroud) 不管这个
<List id="list" items="{/Report}">
<items>
<ObjectListItem press="onSelect" title="{TYPE}"> </ObjectListItem>
</items>
</List>
Run Code Online (Sandbox Code Playgroud)
也不是这个
<List id="list" items="{/Report}" itemPress="onSelect">
<items>
<ObjectListItem title="{TYPE}"> </ObjectListItem>
</items>
</List>
Run Code Online (Sandbox Code Playgroud)
火灾
onSelect : function (oEvent) {
'use strict';
console.log("onSelect");
}
Run Code Online (Sandbox Code Playgroud)
在控制器中.
可能是什么原因导致的 控制台中没有相关的错误消息.
我研究了所有流行的GUI模式 - MVP,MVC,MVVM,最后我决定实现MVP(监督控制器).所以我有以下对象(!).Stage<-View<->Model.重要的是Stage!= View,这是另一个对象.在视图和模型数据之间绑定.此外,我有一个演示者(控制器)处理所有事件,并与视图和模型一起工作,所以View<-ViewInterface<-Controller->Model.现在的问题是如何在视图中引用标签,textAreas等.Javafx允许使用@FXML注释将这些组件注入控制器.但是,使用MVP我需要View中的这些组件,因为视图的所有逻辑都在View中,我不需要它们在控制器中.我所知道的唯一解决方案是:
public class MyView{
private Button button;
public MyView(){
...
button=(Button) root.lookup("#myButton");
}
}
Run Code Online (Sandbox Code Playgroud)
那是通过他们的ID获得参考.但是我不喜欢它.或者我做错了什么或者我理解错了但我认为存在更好的解决方案.请帮帮我找到它.
我想要做的应该是简单的.
我正在尝试将一些表单值发布到返回JSON的mvc控制器.
如果我成功了,我会显示一个弹出窗口,如果我弄错了,我会显示另一个弹出窗口.
但是在控制台中我遇到两个错误:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
browserLink:37 Setting 'XMLHttpRequest.withCredentials' for synchronous requests is deprecated.
Navigated to http://aso.local/
Run Code Online (Sandbox Code Playgroud)
并且页面只是重新加载.
继承我的代码:
$('#mail-message-btn').click(function () {
if ($("form")[0].checkValidity()) {
var formParams = $('#contact-form').serialize();
$.post('/umbraco/surface/Contact/ContactForm', formParams, function (data) {
processData(data);
});
}
});
function processData(data) {
$('#mail-failure').hide();
$('#invalid-email').hide();
$('#empty-field').hide();
$('#mail-success').hide();
if (data.success == 'True') {
$('#mail-message-header').toggleClass('mail-message-error', false);
$('#mail-message-header').toggleClass('mail-message-success', true);
$('#mail-success').show();
$('#mail-message').show();
alert("true");
} else …Run Code Online (Sandbox Code Playgroud) 这是我的代码
<a <%= link_to "open your box", gig_path(@gig), class: "mcnButton", target: "_blank", style: "font-weight: bold;letter-spacing: 0px;line-height: 100%;text-align: center;text-decoration: none;color: #FFFFFF;"%></a>
Run Code Online (Sandbox Code Playgroud)
从上面 <%= link_to "open your box", gig_path(@gig)
注意gig_path(@gig)它给了我的网址http://gigs/3,它运作良好,它发现我需要id:3的问题是,它不提供像这样的完整网址
http://example.com/gigs/3
PS我可以做参考@gig.title,@gig.description它没有问题.
html ruby model-view-controller ruby-on-rails ruby-on-rails-4
我的控制器: Controller/appController/OrdersController.php
我有一个名为的函数nocontact(),我可以将变量传递给nocontact.ctp,如下所示:
$allNoContacts = $result;
$service_charge=$this->ServiceCharge->find('all');
$zero_service_charge=$this->ZeroServiceCharge->find('all');
$zero_service_charge=$zero_service_charge[0]['ZeroServiceCharge']['items'];
$this->set(compact('allNoContacts','service_charge','zero_service_charge'));
Run Code Online (Sandbox Code Playgroud)
如何将此变量传递给OrdersController下的所有视图文件?
在我的MVC研究期间,我只是对这个问题进行了讨论.b是否可能是正确的答案?
您正在设计分布式应用程序.应用程序必须存储特定于单个用户的安全信息.用户注销时必须自动清除数据.您需要将临时信息保存在安全数据存储中.你应该使用哪个数据存储?
A.会话状态
B.数据库存储
C.配置文件属性
D.申请状态
谢谢,