我有一个产品的显示页面,其中显示有关该产品的信息。我在同一显示页面上也有一个查询表,因此用户可以发送有关产品的查询表。查询数据必须保存到Enquery
模型中,EnqueresController
并应具有index
和show
操作对应的内容。
如何在Rails中完成?
任何帮助都将受到高度赞赏。提前致谢!
@product = Product.find(params[:id])
@enquery = Enquery.where("product_id = ?",@product.id).present?
在里面 app/controllers/products_controller.rb
class ProductsController < ApplicationController
// initialize your enquiry model object here
// since you are showing the form on show page
def show
@products = Products.all
@enquiry = Enquiry.new
end
end
之后,在显示视图中 show.html.erb
<%= form_for @enquiry do %>
<%= text_field :modelname, :attribute_name, options %>
....
....
<% end %>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句