I have an existing static HTML page and I wish to add an email signup form. In the interest of time I don’t want to re-create the page as a view. Is it possible to use a static form to submit new emails to a Rails controller?
On the HTML page:
<form method="POST" action="" class="emails">
<input type="text" class="inputbox">
<input type="submit" value="Sign up" class="button" />
</form>
existing Rails controller:
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
The
nameattribute on an input will determine the hash key inparams.So then
will be available through