rails-guide-store/app/controllers/subscribers_controller.rb

21 lines
429 B
Ruby
Raw Normal View History

2025-01-24 17:32:29 +00:00
class SubscribersController < ApplicationController
allow_unauthenticated_access
before_action :set_product
def create
@product.subscribers.where(subscriber_params).first_or_create
redirect_to @product, notice: "You are subscribed!"
end
private
def set_product
@product = Product.find(params[:product_id])
end
def subscriber_params
params.expect(subscriber: [ :email ])
end
end