Ruby on rails Rails 3.1:内容的表单_显示在<;表格></表格>;索引页上的标记
用于部分显示的表单_在产品的显示页面中完美地工作,但是当我将部分添加到产品索引页面中的每个项目时,表单内容会显示出来,但它不在标记的范围内(表单由评级系统样式表单的单选按钮组成(没有ajax-使用提交按钮工作)。如果存在正确的单选按钮,则会选择正确的单选按钮,并且提交似乎仍能正常工作)。 最奇怪的是(在chrome和firefox中),当我查看源代码时,内容在标记内,但当我使用“inspect元素”时,内容在标记外。这是一个问题,因为我的css和jquery在表单元素中找不到内容(该元素在show页面中找到) 有人能解释为什么会发生这种情况,以及我如何解决它吗 详情如下: 红宝石:1.9.3p0 轨道:3.1.3 我有三个模型:用户、产品和口味(外观、香气、味道、质地、饮用性和用于评论的文本区域) 路线:Ruby on rails Rails 3.1:内容的表单_显示在<;表格></表格>;索引页上的标记,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-3.1,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 3.1,用于部分显示的表单_在产品的显示页面中完美地工作,但是当我将部分添加到产品索引页面中的每个项目时,表单内容会显示出来,但它不在标记的范围内(表单由评级系统样式表单的单选按钮组成(没有ajax-使用提交按钮工作)。如果存在正确的单选按钮,则会选择正确的单选按钮,并且提交似乎仍能正常工作)。 最奇怪的是(在chrome和firefox中),当我查看源代码时,内容在标记内,但当我使用“inspect元素”时,内容在标记外。这是一个问题,因为我的css和jquery在表单元素中找不到内容(该元素在sho
Appname::Application.routes.draw do
resources :users
resources :products
resources :taste_notes
class User < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :user_id, :dependent => :destroy
class Product < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :product_id, :dependent => :destroy
class TasteNote < ActiveRecord::Base
attr_accessible :product_id, :appearance, :aroma, :taste,
:texture, :drinkability, :comments
belongs_to :user
belongs_to :product
validates :user_id, :presence => true
validates :product_id, :presence => true
def show
..
...
if @taste_note = current_user.taste_notes.where(:product_id => @product.id).first
else
@taste_note = TasteNote.new(:product_id => @product.id)
end
end
..
...
<%= render :partial => "tnote", :locals => {:product => @product, :taste_note => @taste_note} %>
...
..
..
...
<% get_tasting_note(product) %> <!-- This returns @taste_note -->
<%= render :partial => "tnote", :locals => {:product => product, :taste_note => @taste_note} %>
...
..
<div id="taste_note">
<hr>
<h3>Tasting Notes:</h3>
<%= form_for taste_note, :html => { :class => "rating_ballot_index", :id => "edit_taste_note_#{taste_note.id}" } do |f| %>
<% [ 'appearance', 'aroma', 'taste', 'texture', 'drinkability' ].each do |attribute| %>
<br><br><%= attribute.humanize %><br>
<% (1..5).each do |level| %>
<%= f.label("#{attribute}_#{level}_#{product.id}", content_tag(:span, level), :class=>"taste_note #{attribute}") %>
<%= radio_button_tag("taste_note[#{attribute}]", level, current_user_taste_note("#{attribute}", product.id) == level, :class => "taste_note_button #{attribute}", :id => "taste_note_#{attribute}_#{level}_#{product.id}") %>
<% end %>
<% end %>
<br><br>
<%= f.label :comments %><br><br>
<%= f.text_area :comments, :rows => 5 %>
<br>
<%= f.submit "submit" %>
<% end %>
</div>
型号:
Appname::Application.routes.draw do
resources :users
resources :products
resources :taste_notes
class User < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :user_id, :dependent => :destroy
class Product < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :product_id, :dependent => :destroy
class TasteNote < ActiveRecord::Base
attr_accessible :product_id, :appearance, :aroma, :taste,
:texture, :drinkability, :comments
belongs_to :user
belongs_to :product
validates :user_id, :presence => true
validates :product_id, :presence => true
def show
..
...
if @taste_note = current_user.taste_notes.where(:product_id => @product.id).first
else
@taste_note = TasteNote.new(:product_id => @product.id)
end
end
..
...
<%= render :partial => "tnote", :locals => {:product => @product, :taste_note => @taste_note} %>
...
..
..
...
<% get_tasting_note(product) %> <!-- This returns @taste_note -->
<%= render :partial => "tnote", :locals => {:product => product, :taste_note => @taste_note} %>
...
..
<div id="taste_note">
<hr>
<h3>Tasting Notes:</h3>
<%= form_for taste_note, :html => { :class => "rating_ballot_index", :id => "edit_taste_note_#{taste_note.id}" } do |f| %>
<% [ 'appearance', 'aroma', 'taste', 'texture', 'drinkability' ].each do |attribute| %>
<br><br><%= attribute.humanize %><br>
<% (1..5).each do |level| %>
<%= f.label("#{attribute}_#{level}_#{product.id}", content_tag(:span, level), :class=>"taste_note #{attribute}") %>
<%= radio_button_tag("taste_note[#{attribute}]", level, current_user_taste_note("#{attribute}", product.id) == level, :class => "taste_note_button #{attribute}", :id => "taste_note_#{attribute}_#{level}_#{product.id}") %>
<% end %>
<% end %>
<br><br>
<%= f.label :comments %><br><br>
<%= f.text_area :comments, :rows => 5 %>
<br>
<%= f.submit "submit" %>
<% end %>
</div>
产品展示页面调用部分:
Appname::Application.routes.draw do
resources :users
resources :products
resources :taste_notes
class User < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :user_id, :dependent => :destroy
class Product < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :product_id, :dependent => :destroy
class TasteNote < ActiveRecord::Base
attr_accessible :product_id, :appearance, :aroma, :taste,
:texture, :drinkability, :comments
belongs_to :user
belongs_to :product
validates :user_id, :presence => true
validates :product_id, :presence => true
def show
..
...
if @taste_note = current_user.taste_notes.where(:product_id => @product.id).first
else
@taste_note = TasteNote.new(:product_id => @product.id)
end
end
..
...
<%= render :partial => "tnote", :locals => {:product => @product, :taste_note => @taste_note} %>
...
..
..
...
<% get_tasting_note(product) %> <!-- This returns @taste_note -->
<%= render :partial => "tnote", :locals => {:product => product, :taste_note => @taste_note} %>
...
..
<div id="taste_note">
<hr>
<h3>Tasting Notes:</h3>
<%= form_for taste_note, :html => { :class => "rating_ballot_index", :id => "edit_taste_note_#{taste_note.id}" } do |f| %>
<% [ 'appearance', 'aroma', 'taste', 'texture', 'drinkability' ].each do |attribute| %>
<br><br><%= attribute.humanize %><br>
<% (1..5).each do |level| %>
<%= f.label("#{attribute}_#{level}_#{product.id}", content_tag(:span, level), :class=>"taste_note #{attribute}") %>
<%= radio_button_tag("taste_note[#{attribute}]", level, current_user_taste_note("#{attribute}", product.id) == level, :class => "taste_note_button #{attribute}", :id => "taste_note_#{attribute}_#{level}_#{product.id}") %>
<% end %>
<% end %>
<br><br>
<%= f.label :comments %><br><br>
<%= f.text_area :comments, :rows => 5 %>
<br>
<%= f.submit "submit" %>
<% end %>
</div>
口味说明部分(\u tnote.html.erb):
Appname::Application.routes.draw do
resources :users
resources :products
resources :taste_notes
class User < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :user_id, :dependent => :destroy
class Product < ActiveRecord::Base
has_many :taste_notes, :foreign_key => :product_id, :dependent => :destroy
class TasteNote < ActiveRecord::Base
attr_accessible :product_id, :appearance, :aroma, :taste,
:texture, :drinkability, :comments
belongs_to :user
belongs_to :product
validates :user_id, :presence => true
validates :product_id, :presence => true
def show
..
...
if @taste_note = current_user.taste_notes.where(:product_id => @product.id).first
else
@taste_note = TasteNote.new(:product_id => @product.id)
end
end
..
...
<%= render :partial => "tnote", :locals => {:product => @product, :taste_note => @taste_note} %>
...
..
..
...
<% get_tasting_note(product) %> <!-- This returns @taste_note -->
<%= render :partial => "tnote", :locals => {:product => product, :taste_note => @taste_note} %>
...
..
<div id="taste_note">
<hr>
<h3>Tasting Notes:</h3>
<%= form_for taste_note, :html => { :class => "rating_ballot_index", :id => "edit_taste_note_#{taste_note.id}" } do |f| %>
<% [ 'appearance', 'aroma', 'taste', 'texture', 'drinkability' ].each do |attribute| %>
<br><br><%= attribute.humanize %><br>
<% (1..5).each do |level| %>
<%= f.label("#{attribute}_#{level}_#{product.id}", content_tag(:span, level), :class=>"taste_note #{attribute}") %>
<%= radio_button_tag("taste_note[#{attribute}]", level, current_user_taste_note("#{attribute}", product.id) == level, :class => "taste_note_button #{attribute}", :id => "taste_note_#{attribute}_#{level}_#{product.id}") %>
<% end %>
<% end %>
<br><br>
<%= f.label :comments %><br><br>
<%= f.text_area :comments, :rows => 5 %>
<br>
<%= f.submit "submit" %>
<% end %>
</div>
愚蠢的错误。
我有一个导致所有问题的开放标签。也许您正试图在表单中嵌套表单?这是不允许的,您的浏览器将尝试更正它。不,这似乎不是问题(除非我做错了什么)。我尝试允许嵌套属性,但没有效果。此外,我还有一个类似的“最爱”物品的表格,它与味觉笔记完美地显示在同一个位置。关于可能导致问题的原因,还有其他建议吗?我已经想了两天了。我被难住了。好吧,经过两天的拷问,我发现我有一个打开的标签,这是导致所有问题的原因。你可能想回答你的问题并把它标记为接受,你应该考虑切换到HAML。