Tag: 表单助手

Rails嵌套表单,其中预定义字段为复选框

我正在制作一个包含Room和RoomAttribute模型的酒店应用程序。 这两个模型通过连接表在彼此之间具有many_to_many关系。 每个模型的属性如下: Room – room_number , room_type (例如“豪华”或“套房”)和price 。 RoomAttributes – name (例如“无线互联网”,“有线电视”,“浴缸”)。 用户将首先创建一组房间属性,以便每次创建新房间时都可以选择这些房间属性。 例如,有些房间可能有无线互联网,有些则没有。 app/views/rooms/new.html.erb的代码是(我对使用原始html表示歉意)。 <form action="” method=”post”> <input type="hidden" name="authenticity_token" value="”> Room Number: Type: Price: Attributes: <input type="checkbox" name="room[room_attributes_ids][]" value="”> 我正在使用Rails 4,我想就以下内容征求意见: 使用表单助手或formtastic设置表单,以便它已经输出所有预定义的房间属性,用户只需通过复选框选择要包含在房间中的属性。 编写RoomController#create方法,以便将嵌套的RoomAttribute模型设置为房间属性。 我的app/models/room.rb是否需要accepts_nested_attributes_for :room_attributes app/models/room.rb ? 如何在此方案中合并强参数。 我读过我应该用的 params.require(:room).permit(:room_number, :room_type, :price, room_attributes_attributes: [:id]) 但这不适合我。 谢谢! 🙂

在Rails中使用check_box_tag的自定义ID

在rails中使用check_box_tag帮助程序时如何设置自定义ID? 我有一个循环,它根据集合创建了一堆复选框: – subject.syllabus_references.each do |sr| = check_box_tag ‘question[syllabus_reference]’, sr.id, :id => sr.id = label_tag sr.id, sr.name 我想设置一个自定义ID,以便我的复选框标签正常工作,但我似乎无法弄清楚如何(:id => sr.id不起作用……)。 问题也可能出在我定义标签的方式上,所以如果我可以在没有设置自定义ID的情况下引用正确的复选框,那么也可以……

添加属性到rails helper文本字段?

我有一个来自devise的rails helper文本字段,它使用html并自动validationtype=”email”字段。 我想添加属性novalidate=’novalidate’ ,但我不知道如何..inheritance人代码..任何建议? resource_name, :url => session_path(resource_name) ) do |f| %>