我有一个为房屋建模的 Rails 应用程序。有一个具有许多参数的房屋模型has_many rooms。一个房间有一个house_id和一个名称。我还使用http://github.com/ryanb/complex-form-examples来允许许多灯光并small_appliances添加到房间中。complex-form-example 使用 RJS 和分部来完成此任务。
有一个称为计算器的控制器,用户将使用它来访问应用程序。当按下计算器上的提交按钮时,它会重定向到一个add_rooms页面(位于app/views/calculator/add_rooms.html.erb)页面,用户可以在其中add rooms访问房屋。add_rooms 页面使用部分 from app/views/rooms/_room_form.html.erb. 我无法显示它,因为 Rails 总是在 app/views/calculator 文件夹中寻找内容。
我怎样才能显示这个?另请注意,我在保存房间时需要保存房屋的 id。
这是所有相关代码(我希望):
如果我注释掉这两个add_child_link。页面呈现。但是,当我单击“提交”时,我收到一条新的错误消息:
CalculatorController#add_room 中的 ActiveRecord::AssociationTypeMismatch 预期为 SmallAppliance(#49096610),得到了 Array(#1560620) RAILS_ROOT: C:/Users/ryan/Downloads/react 应用追踪 | 框架跟踪 | 完整追踪 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_proxy.rb:263:在`raise_on_type_mismatch'中 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_collection.rb:320:在“替换”中 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_collection.rb:320:在“每个”中 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations/association_collection.rb:320:在“替换”中 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/associations.rb:1322:in `small_appliances=' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2744:在“发送”中 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2744:in `attributes=' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2740:在“每个”中 C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2740:in `attributes=' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.4/lib/active_record/base.rb:2438:在“初始化”中 C:/Users/ryan/Downloads/react/app/controllers/calculator_controller.rb:31:在“新”中 C:/Users/ryan/Downloads/react/app/controllers/calculator_controller.rb:31:在“add_room”中
如果我删除small_application部分,同样的事情也会发生在light上。accepts_nested_attributes_for我认为这与房间模型有关。我添加了下面的代码。我还添加了 house.rb 代码。
class Room < ActiveRecord::Base
belongs_to :house
has_many …Run Code Online (Sandbox Code Playgroud) 我有一个模拟房子的应用程序.House has_many Rooms,Rooms has_many Lights和Small_appliances等.我还有一个名为Calculator的控制器,它是应用程序的访问方式.使用计算器控制器将数据添加到房屋(及其房间).然后生成一个报告,该报告位于app/views/calculator/report.html.erb.
我的问题是报告的所有计算和逻辑应该在哪里?目前我在视图中都有这一切,在calculator_helper中有一些东西.通常这会出现在模型中,对吧?但是Calculator没有生成的模型.这是什么标准?
这是计算器控制器.
class CalculatorController < ApplicationController
def index
end
def save_house
@house = House.new(params[:house])
respond_to do |format|
if @house.save
format.html { render :action => 'add_rooms', :id => @house }
format.xml { render :xml => @house, :status => :created, :location => @house }
else
format.html { render :action => 'index' }
format.xml { render :xml => @house.errors, :status => :unprocessable_entity }
end
end
end
def add_rooms
@house = House.find(params[:id])
@rooms = Room.find_by_house_id(@house.id)
rescue ActiveRecord::RecordNotFound
logger.error("Attempt to …Run Code Online (Sandbox Code Playgroud) 我想生成一个数据透视表,每个数据透视列有 2 个总和聚合。然后在枢轴列的右侧,我想要一些总列。最后,枢轴列的数量是动态的。我的首选结果如下:
我的数据如下所示:
从这个答案来看,我已经非常接近解决它了。这是我所拥有的:
SELECT *
FROM (
SELECT B.SiteID, R.BuildingID, C.*
FROM Rooms R JOIN Buildings B
ON R.BuildingID = B.BuildingID
CROSS APPLY (
VALUES(RTRIM(RoomType) + ' NASF', AreaNASF)
,(RTRIM(RoomType) + ' RSF', AreaRSF)
) C (Item,Value)
) src
PIVOT (
SUM([Value])
FOR [Item] IN ([CONFERENCE NASF], [CONFERENCE RSF], [OFFICE NASF], [OFFICE RSF], [STORAGE NASF], [STORAGE RSF])
) pvt
Run Code Online (Sandbox Code Playgroud)
其产生:
我的印象是我必须在 SQL 之外执行两行标题。我需要帮助的是如何添加总列数。STUFF另外,除了我在很多地方看到的解决方案之外,还有更好的动态列解决方案吗?
以下是创建示例数据的 SQL:
CREATE TABLE Buildings (
BuildingID CHAR(12),
SiteID CHAR(12),
Name …Run Code Online (Sandbox Code Playgroud) 我正在尝试为Raphael图像元素添加边框,描边或阴影.我的最终目标是拥有一个动画的发光边框.我已经使用JavaScript 在标准HTML元素上实现了这一点,但我无法找到使用Raphael的方法.
我已阅读建议使用带图像填充的rect的帖子,但这不起作用,因为我需要图像可扩展.我还没有找到一种方法来设置图像填充的尺寸.
有没有办法使用JavaScript访问Raphael.image元素的样式属性?
谢谢,
aggregate ×1
css ×1
helper ×1
image ×1
javascript ×1
model ×1
partial ×1
pivot ×1
pivot-table ×1
raphael ×1
render ×1
sql-server ×1
t-sql ×1