我有一个带有'基金'集合的simple_form,它目前将基金类别的名称和基金的id
传递给控制器。这很好,但现在我还需要发送一个额外的参数以及基金的id
。我需要通过与该类别相关联的percent
数字发送。
我不知道如何实现这个目标?
<%= simple_form_for portfolio do |f| %>
<div class='row'>
<div class='large-9 columns portfolio'>
<table>
<tr>
<th>PERCENT (%)</th>
<th>Select Fund</th>
</tr>
<% portfolio.demo_portfolio_distributions.sort_by(&:fc_sector).each do |distribution| %>
<tr>
<td>
<%= distribution.percent %>
</td>
<td>
<%= f.simple_fields_for :portfolio_items_attributes do |demo_distribution| %>
<span class='legend-key <%= distribution.fc_sector_types.downcase.gsub(/\s/,'-') %>-key'>•</span>
<%= demo_distribution.input "#{distribution.fc_sector.gsub(/\(.*\)/, "")}", as: :select, collection: distribution.funds, required: false,prompt: 'Select fund' %>
<% end %>
</td>
</tr>
<tr>
<td>
</td>
<td>
<%= link_to 'Add another fund', demo_portfolio_demo_portfolio_distributions_path(portfolio, distribution: distribution), method: :post, remote: true %>
</td>
</tr>
<% end %>
<noscript>
<%= f.submit %>
</noscript>
</table>
</div>
<div class='large-2 columns portfolio-buttons'>
<%= render 'demo_portfolio_distributions/manage_demo', :f => f, portfolio: portfolio %>
</div>
</div>
这就是现在的params:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"KA8u0WHfUsXfHfBn5aYhHkxOXqBS8UftJ0vTqkzWuAI=",
"demo_portfolio"=>
{"portfolio_items_attributes"=>
{"absolute return funds"=>"123",
"asian equity "=>"134",
"commercial property"=>"456",
"corporate bond"=>"678",
"european equity "=>"654",
"high yield bond"=>"900",
"strategic bond"=>"000",
"uk equity "=>"765",
"uk smaller companies"=>"345",
"us equity "=>"666"}},
"commit"=>"Save Portfolio",
"action"=>"snapshot",
"controller"=>"demo_portfolios",
"id"=>"335"}
模型:
class DemoPortfolioDistribution < ActiveRecord::Base
# attr_accessible :title, :body
attr_accessible :demo_portfolio_id, :fc_sector, :percent
belongs_to :demo_portfolio
end
#
class DemoPortfolio < ActiveRecord::Base
# attr_accessible :title, :body
attr_accessible :name, :demo_portfolio_distributions_attributes, :risk, :is_example
has_many :demo_portfolio_distributions
accepts_nested_attributes_for :demo_portfolio_distributions, allow_destroy: true
end