Created
October 23, 2017 22:55
-
-
Save telegraham/11117df522e0a86730799f839599ad81 to your computer and use it in GitHub Desktop.
andreea and her horses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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