首页 \ 问答 \ 覆盖Rails中的默认路由(Override default routing in Rails)

覆盖Rails中的默认路由(Override default routing in Rails)

我们可以覆盖Rails提供的资源的默认路由吗? 在我的应用程序中,我希望只能通过put方法访问new.html.erb。 但是,通过定义map.resources :model将使用get方法访问new.html.erb,我想改变它。 我可以吗?


Can we override the default routing for resources provided by Rails? In my app I want new.html.erb to be accessed only by put method. But, by defining map.resources :model will give access with get method to new.html.erb and I want to change that. Can I?


原文:
更新时间:2022-08-07 06:08

最满意答案

当然,我可能会弄错,但它看起来像你的LINQ查询的COUNT(*)正在分组上运行,而不是在UserCategoryUserCategory

如果用g.Count()替换g.Count()会发生什么?

如果表没有行, COUNT(*)将不返回1。 只有当表中有1行或更多行并且其中一行或多行中的ProjectId列为NULLCOUNT(ProjectId)才会低于COUNT(*)


I figured it out. It would appear that because it was doing COUNT(*), it would return null when the project id was null, as mentioned by Jay. This would then be seen as 1 in the count, screwing up the results.

Changing the count part of the select to below works nicely:

CategoryCount = g.Where(grp => grp != null).Count()

Thanks for your replies

相关问答

更多
  • context.UserProfile .Where(x=>x.CompletedSetup==1 && context.webpages_UsersInRoles.Any(u=>u.UserId == x.UserId && u.RoleId == 4)) .GroupBy(x=>new {x.UserLevel, x.StudioId) .Select(x=>new {UserLevel = x.Key.UserLevel, StudioId = x.Key.StudioId, count=x.Coun ...
  • 尝试这个 var test = session.Query() .GroupBy(c => new { c.Var1, c.Var2, c.Var3 }) .Select(d=> new { var1 = d.Key.var1,var2 = d.Key.var2,var3=d.Key.var3,records = d.ToList()}) .Where(e => e.record ...
  • 对于具有许多关系的修改模型,请考虑对原始查询进行以下修改: var top5jobfunctions = JobSearchResults.SelectMany(j => j.SearchString.Select(s => new {j,s})) .Where(j => (j.s != null)) .GroupBy(j => new { j.s.JobFunction.JobFunctionId, j.s.JobFunctio ...
  • 您按多列分组: from table in context.table group new{table.UserID,table.Date} by new{table.ID,table.Name} into grp orderby grp.Key.ID descending select new { ID = grp.Key.ID, Date=grp.FirstOrDefault().Date, Name=grp.Key.Name, Users = grp.Select(e= ...
  • 只需使用Count方法: from buildinguser in db.GetTable() join building in db.GetTable() on buildinguser.ID_BUILDING equals building.ID join user in db.GetTable() on buildinguser.ID_USER equals user.ID group building by building.NAME in ...
  • 尝试以下操作: (from c in AllContracts group c by new {c.StatusId, c.StatusDescription} into g select new { StatusId = g.Key.StatusId, StatusDescription = g.Key.StatusDescription, CountOf = g.Count() }).OrderBy(item => item.StatusId) Try the followin ...
  • 根据您的要求 每个id应仅包含在一个状态下,并且应根据每个状态更新的最新日期进行 首先需要按Id分组,从每个分组中获取具有最新日期的元素,然后按Status对结果进行分组: var query = from e in (from e in this.logRepository.GetQuery(null) group e by e.Id into g select g.OrderByDescending(e => e.Date).First ...
  • 你很近。 试试以下 var names= db.User.GroupBy(fu => fu.Name) .Select(g => new { Name=g.Key, Count = g.Count() }); You are very close. Try following var names= db.User.GroupBy(fu => fu.Name) .Select(g => new { Name=g.Key, Count = g.Count ...
  • 当然,我可能会弄错,但它看起来像你的LINQ查询的COUNT(*)正在分组上运行,而不是在UserCategory上UserCategory 。 如果用g.Count()替换g.Count()会发生什么? 如果表没有行, COUNT(*)将不返回1。 只有当表中有1行或更多行并且其中一行或多行中的ProjectId列为NULL , COUNT(ProjectId)才会低于COUNT(*) 。 I figured it out. It would appear that because it was doin ...
  • 鉴于以下数据: Dim table = { New With { .Name = "A", .Consumed = "Flavor 1" }, New With { .Name = "B", .Consumed = "Flavor 2" }, New With { .Name = "C", .Consumed = "Flavor 1" }, New With { .Name = "C", .Consumed = "Flavor 3" }, New With { ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。