私は多数のプロジェクトに取り組んできました。そこでは、HTML フォーム内の新しいオブジェクトの属性の設定と呼び出し時の両方を見てきました。Model.new(foo: 'bar')
「ベストプラクティス」の方法でこれを行う正しい方法はどれですか?
形:
<%= form_for User.new, remote: true do |f| %>
<%= f.hidden_field :foo, value: "bar" %>
<%= f.text_field :email %>
<% end %>
インスタンス変数:
#Obviously this is set in the Controller
@user = User.new(foo: "bar")
<%= form_for @user, remote: true do |f| %>
<%= f.text_field :email %>
<% end %>