Skip to content

Instantly share code, notes, and snippets.

@cdimartino
Last active February 12, 2016 22:38
Show Gist options
  • Save cdimartino/f84efc21e84a78bce98b to your computer and use it in GitHub Desktop.
Save cdimartino/f84efc21e84a78bce98b to your computer and use it in GitHub Desktop.
Proper form input field naming conventions

If you make your form fields like:

<form method='PUT' action='/entries'>
  <input type='text' name='entry[title]' />
  <input type='text' name='entry[content'] />
</form>

Then your Ruby code becomes more straightforward:

put '/entries/:entry_id' do
  @post = Entry.find(params[:entry_id])
  if @post.update(params[:entry])
    redirect "/entries/#{@post.id}"
  else
    render :new, locals: { errors: @post.errors.full_messages }
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment