Rails ver。 5.0.0.1如何通过link_to传递参数到
我想通过组合SHOW页面中的link_to创建并分配一个新属性。该链接应该传递portfolio_id作为参数,并在完成剩余的财产形式后保存。
我见过这个问题多次提问,但由于某种原因,在我自己的应用程序中应用正确的答案是行不通的。任何帮助将不胜感激,谢谢!
# portfolio show.html.erb
<%= link_to 'Add New Property To This Portfolio', new_property_path(:portfolio_id => @portfolio.id) %>
# properties controller
def new
@portfolio = :portfolio
@property = Property.new(params[:portfolio_id => @portfolio])
end
# portfolio model
has_many :properties
# property model
belongs_to :portfolio
accepts_nested_attributes_for :portfolio