Skip to content

Instantly share code, notes, and snippets.

@telegraham
Created October 23, 2017 22:55
Show Gist options
  • Save telegraham/11117df522e0a86730799f839599ad81 to your computer and use it in GitHub Desktop.
Save telegraham/11117df522e0a86730799f839599ad81 to your computer and use it in GitHub Desktop.
andreea and her horses
<li class="js--horseListItem list-item col-1-2">
<a class="js--horseLink big fancy-text light-link" href="/horses/<%= andreea.id%>"><%= andreea.name %></a>
<span class="js--horseDetails"></span>
</li>
post '/horses' do
@horse = Horse.new(params[:horse])
if request.xhr?
if @horse.save
#send back a horse partial
erb :"/horses/_horse_list_item", layout: false, locals: { andreea: @horse }
else
#bring back some errors
status 422
erb :"/horses/_new_horse_form", layout: false
end
else
if @horse.save
redirect "/horses/#{@horse.id}"
else
erb :"/horses/new"
end
end
end
<h1 class="big">Meet the Herd</h1>
<ul class="list js--horseList">
<% @horses.each do |horse| %>
<%= erb :'horses/_horse_list_item', locals: { andreea: horse } %>
<% end %>
</ul>
<form class="js--newHorseForm flex flex-column" method="GET" action="/horses/new">
<button type="submit" class="button dark">Add a Horse</button>
</form>
<div class="js--newHorseFormContainer">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment