Я работаю над подпиской на приложение, но я стремился создать подписку на шоу / странице продукта. Из-за ошибки
ActionController :: ParameterMissing (параметр отсутствует или значение пусто: подписка):
routes.rb
resources :products do
resources :subscriptions, only: [:create]
end
продукты / show.html.erb
<div class="subscribe">
<%= form_with(model: @subscription, url: product_subscriptions_path(product_id: @product.id)) do |f| %>
<div>
<%= f.text_field :email %>
<%= f.submit "Register", class: "btn"%>
</div>
<% end %>
</div>
products_controller.rb
def show
@product = Product.find_by_id(params[:id])
@subscription = Subscription.new
end
subscription_controller.rb
def create
@product = Product.find(params[:product_id])
@subscription = @product.subscriptions.build(create_params)
@subscription.save
end
def create_params
params.require(:subscription).permit(:email, :product_id)
end