Skip to content

Instantly share code, notes, and snippets.

View zacksheppard's full-sized avatar

Zack Sheppard zacksheppard

View GitHub Profile
layout title date comments categories
post
Removing leading and trailing spaces and &nbsp in Ruby
2014-10-17 15:46:09 -0400
true

tl;dr

  • If .strip isn't working, try .gsub(/\A[[:space:]]+|[[:space:]]+\z/, '')
@zacksheppard
zacksheppard / rails_ajax_forms.md
Last active August 29, 2015 14:04
Submitting AJAX forms in rails

Notes showing different ways to us AJAX forms in Rails. We will use a Todo list as an example domain for the examples.

Lowest level of abstraction


views/lists/index.erb.html This will create the list input form (Note: This should also work in Sinatra)

<% form_for List.new do |f| %>
@zacksheppard
zacksheppard / gist:fda30fa8fa54f6c4bf5f
Created July 10, 2014 12:39
Rails form_for example

From: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html

To create a new person you typically set up a new instance of Person in the PeopleController#new action, @person, and in the view template pass that object to form_for:

<%= form_for @person do |f| %>
  <%= f.label :first_name %>:
  <%= f.text_field :first_name %><br />

  <%= f.label :last_name %>:
  <%= f.text_field :last_name %><br />