我有3个型号:报价,客户和项目.每个报价都有一个客户和一个项目.当我按下提交按钮时,我想在各自的表中创建一个新报价,一个新客户和一个新项目.我已经查看了其他问题和railscast,要么它们不适用于我的情况,要么我不知道如何实现它们.
quote.rb
class Quote < ActiveRecord::Base
attr_accessible :quote_number
has_one :customer
has_one :item
end
Run Code Online (Sandbox Code Playgroud)
customer.rb
class Customer < ActiveRecord::Base
attr_accessible :firstname, :lastname
#unsure of what to put here
#a customer can have multiple quotes, so would i use has_many or belongs_to?
belongs_to :quote
end
Run Code Online (Sandbox Code Playgroud)
item.rb的
class Item < ActiveRecord::Base
attr_accessible :name, :description
#also unsure about this
#each item can also be in multiple quotes
belongs_to :quote
Run Code Online (Sandbox Code Playgroud)
quotes_controller.rb
class QuotesController < ApplicationController
def index
@quote = Quote.new
@customer = Customer.new
@item = …Run Code Online (Sandbox Code Playgroud) 如果你会看到这个例子:http://jsfiddle.net/UTjbm/1/
我想要它,以便当第二个选择标记更改时,将出现一个警告,其中包含第一个选择选项文本.
根据我迄今为止所研究的内容,我希望这会有效,但唉,事实并非如此.我正在使用jquery.
我的jsfiddle代码:
<select id="select_a">
<option value='1'>woot1</option>
<option value='2'>woot2</option>
<option value='3'>woot3</option>
<option value='4'>woot4</option>
</select>
<select id="select_b">
<option value='1'>notwoot1</option>
<option value='2'>notwoot2</option>
<option value='3'>notwoot3</option>
<option value='4'>notwoot4</option>
</select>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
$("#select_b").change(function (){
alert($("#select_a").options[$("#select_a").selectedIndex].text);
})
Run Code Online (Sandbox Code Playgroud)