我在我的模型中使用远程属性来检查重复的页面标题如下
public class Page
{
[Remote("CheckDuplicate", "Page", ErrorMessage = "Title already taken")]
public string Title { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
在控制器中,我将根据" 检查 "结果返回JsonResult数据,如下所示:
public JsonResult CheckDuplicate(string Title)
{
var result = db.Pages.Where(a => a.Title == Title).Count() == 0;
return Json(result, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
这在Create动作中工作正常,但问题是,它限制了我编辑现有页面,因为它正在检查相同的查询.
如何解决这个问题呢?请建议我
如何将这种复杂模型与包含多个对象的多个图层绑定?现在我将模型传递给视图 - (填充表单/复选框树),我想要准确的模型(SubjectSelectionModel),但它没有正确绑定.
任何人都可以详细说明我需要采取的过程,以便在我看来正确绑定这些过程吗?
查看型号:
public class SubjectSelectionModel
{
public IList<Subject> Subjects { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
学科分类:
public class Subject
{
public String Name { get; set; }
public IList<Bin> Bins { get; set; }
public Subject()
{
}
public Subject(IList<Course> courses)
{
}
}
Run Code Online (Sandbox Code Playgroud)
Bin类:
public class Bin
{
public Subject Subject { get; set; }
public int Amount { get; set; }
public IList<Foo> Foos { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Foo类:
public class Foo
{
public int …Run Code Online (Sandbox Code Playgroud) 你可以帮我解决以下问题吗?我知道这是基本的,但我似乎缺少一些非常基本的东西.当我问SectionEdit.new时,事情似乎出错,虽然我指的是正确的类名.谢谢你的帮助.
这是我得到的错误.
$ edit = SectionEdit.new
NameError: undefined local variable or method `class_name' for #<Class:0x103675008>
from /Library/Ruby/Gems/1.8/gems/activerecord-3.2.8/lib/active_record/dynamic_matchers.rb:50:in `method_missing'
from /Users/seydoukonate/Sites/simple_cms/app/models/section_edit.rb:3
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `load'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `load_file'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:639:in `new_constants_in'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:468:in `load_file'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:353:in `require_or_load'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:502:in `load_missing_constant'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:192:in `const_missing'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `each'
from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:190:in `const_missing'
from (irb):14
Run Code Online (Sandbox Code Playgroud)
我已经将模型"页面"定义如下
class SectionEdit < ActiveRecord::Base
attr_accessible :admin_user_id, :section_id, :summary
belongs_to :editor, class_name => "AdminUser", :foreign_key => 'admin_user_id'
belongs_to :section
end
Run Code Online (Sandbox Code Playgroud)
管理员用户
class AdminUser < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email, :username
has_and_belongs_to_many …Run Code Online (Sandbox Code Playgroud) 你能告诉我如何逐步使用求解器Z3吗?而且,当我使用时v.name(),如何才能获得没有命题价值的模型?比如,在调用程序后cout<<v.name()<<m.get_const_interp(v);,我们可以得到模型
x = 3, p = true, y = 4,因为我不需要p = true,可以从模型集中删除吗?
我是Codeigniter的新手并尝试编辑在数据库中输入的字段.我也从CI教程中学习本教程.当我试图运行该网站时,我得到了错误
Message: Undefined property: Books::$query
Filename: core/Model.php
Line Number: 51
Run Code Online (Sandbox Code Playgroud)
但我没有修改核心文件中的任何代码.我的模特book_model.php是
function get($id)
{
//echo $id;
$this->load->database();
// echo 'sda';
$query = $this->db->get_where('books',array('id'=>$id));
echo 'test';
$a = $this->query->row_array();
var_dump($a);
return $a;
}
Run Code Online (Sandbox Code Playgroud)
我可以看到回声,但var_dump()没有显示任何内容.
rails generate model FooTable name:string
rails generate model foo_table name:string
Run Code Online (Sandbox Code Playgroud)
哪一个是正确的方法?
看来我在这里只停留在一个简单的点 - 我有一个名为"User"的模型,其中一个名为"username"的字段设置为唯一.
让我们假设我的网站上有新访问者,想要注册,必须选择用户名并点击"注册".在这种情况下,我的字段"username"必须是attr_accessible.
我现在想要完成的是当用户编辑他/她的帐户时,字段"用户名"不再可编辑.
我怎么能意识到这一点?
Bouns-Karma:我正在使用带有设计的CanCan,因此具有admin-role的用户可以改变给定用户的用户名的解决方案将是超级的!我的想法告诉我"除非user.admin?" 但是我的编码时间太长了.
无论如何 - 我希望会有一些答案:)
从昨天开始,我正在阅读Java在线文档,我注意到它更多地关注实践,而不是描述该库的机制.
由于IO包中有很多类,我如何理解何时使用以及如何使用它们?我对它的模型比对它的内容更感兴趣.
欢迎提供建议和手册.
先感谢您...
我试图创建具有xpos,ypos,type和存储在其中的modelInstance的3D立方体.当我尝试运行该程序时,我收到此错误:
线程"LWJGL Application"中的异常org.lwjgl.opengl.OpenGLException:禁用数组缓冲区对象时不能使用偏移量
我该如何启用它?
这是我收到错误的类:
package com.me.the_unknown;
import java.util.ArrayList;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.graphics.g3d.materials.Material;
import com.badlogic.gdx.graphics.g3d.materials.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
public class Blocks {
public static ArrayList<Float> blockX = new ArrayList<Float>();
public static ArrayList<Float> blockY = new ArrayList<Float>();
public static ArrayList<Integer> blockType = new ArrayList<Integer>();
public static ArrayList<ModelInstance> blockModelInstance = new ArrayList<ModelInstance>();
public static ModelBatch modelBatch;
private static ModelBuilder modelBuilder;
//Textures
public static Texture stonebrick = new Texture("data/blocks/stonebrick.png");
public static Texture gravel = new Texture("data/blocks/gravel.png"); …Run Code Online (Sandbox Code Playgroud) 视图:
def details(request, id):
event = Event.objects.filter(id=id)
return render(request, 'details.html', {'Event' : event})
Run Code Online (Sandbox Code Playgroud)
模板:
{% if Event %}
<h1>Event Name: {{ Event.name }}</h1>
{% else %}
No Event.
{% endif %}
Run Code Online (Sandbox Code Playgroud)
模型:
class Event(models.Model):
name = models.CharField(max_length = 30)
artist = models.ManyToManyField(Artist)
venue = models.ForeignKey(Venue)
event_date = models.DateTimeField('event date')
on_sale = models.DateTimeField('on sale time')
def __unicode__(self):
return unicode(self.name)
Run Code Online (Sandbox Code Playgroud)
当我加载页面时,它只是加载Event Name:.当我删除.name属性时,它会加载事件,因为它在数据库中输入,但它不会从对象加载任何属性.感谢任何帮助/建议.
model ×10
java ×2
action ×1
arraylist ×1
attributes ×1
c# ×1
codeigniter ×1
controller ×1
devise ×1
django ×1
java-io ×1
libgdx ×1
php ×1
templates ×1
z3 ×1