我有一个现有的静态 HTML 页面,我希望添加一个电子邮件注册表单。为了节省时间,我不想将页面重新创建为视图。是否可以使用静态表单向 Rails 控制器提交新电子邮件?
在 HTML 页面上:
<form method="POST" action="" class="emails">
<input type="text" class="inputbox">
<input type="submit" value="Sign up" class="button" />
</form>
现有的 Rails 控制器:
def create
@subscription = Subscription.new(params[:subscription])
respond_to do |format|
if @subscription.save
format.html { redirect_to @subscription, notice: 'Subscription was successfully created.' }
format.json { render json: @subscription, status: :created, location: @subscription }
else
format.html { render action: "new" }
format.json { render json: @subscription.errors, status: :unprocessable_entity }
end
end
end