thirdhaf
thirdhaf

Reputation: 138

How can I submit form content to a Rails app from a static page?

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

Upvotes: 3

Views: 1002

Answers (2)

Raghu
Raghu

Reputation: 2563

Use <input type="text" class="inputbox" name ="subscription[name]"> assuming that name is the field in your subscription table.

Upvotes: 1

user1454117
user1454117

Reputation:

The name attribute on an input will determine the hash key in params.

So then

<input type="text" name="foo">

will be available through

params[:foo]

Upvotes: 3

Related Questions