Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
Refactor snack index view and add javascript
Browse files Browse the repository at this point in the history
Javascript will show and hide the new snack submission form
  • Loading branch information
rweald committed Jan 9, 2011
1 parent c214485 commit c9706ac
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/controllers/snacks_controller.rb
Expand Up @@ -6,6 +6,7 @@ def new
def index
@snacks = Snack.all()
render :action => "index"
@snack = Snack.new
end

end
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -4,6 +4,7 @@
<title>SnackPicker</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag "jquery.min.js" %>
<%= csrf_meta_tag %>
</head>
<body>
Expand Down
23 changes: 23 additions & 0 deletions app/views/snacks/_snack_form.html.erb
@@ -0,0 +1,23 @@
<div class="form_container">
<% form_for :snack, @snack, :url => {:controller => "snacks", :action => "create"} do |f| -%>
<div class="field">
<%= f.label :name, "Name" %>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :category, "Category" %>
<%= f.text_field :category %>
</div>
<div class="field">
<%= f.label :price, "Price" %>
<%= f.text_field :price %>
</div>
<div class="field">
<%= f.label :quantity, "Quantity" %>
<%= f.text_field :quantity %>
</div>
<div class="submission">
<%= f.submit "Add New Snack" %>
</div>
<% end -%>
</div>
19 changes: 18 additions & 1 deletion app/views/snacks/index.html.erb
Expand Up @@ -14,7 +14,7 @@
<tr>
<td class="name"> <%= item.name %> </td>
<td class="quantity"><%= item.quantity %> </td>
<td class="price"> <%= item.price %> </td>
<td class="price"> $ <%= item.price %> </td>
<td class="votes"> <%= item.votes %> </td>
</tr>
<% end %>
Expand All @@ -24,3 +24,20 @@

</tbody>
</table>

<div class="form_instructions">
<p>Don't see your snack on the list? </p>
<center><button id="show_form">Click Here to Add it</button> </center>
</div>

<%= render :partial => "snack_form" %>

<script type="text/javascript">
$(function () {
$("#show_form").click(function () {
$(".form_container").toggle();
});

});
</script>

33 changes: 32 additions & 1 deletion public/stylesheets/style.css
Expand Up @@ -80,4 +80,35 @@ table td:first-child{
table tbody tr:hover{
background-color:yellow;
cursor: pointer;
}
}

/*styling for the new snack form*/
.form_instructions{
width: 80%;
margin: auto;
text-align: center;
margin-top: 20px;
}

.form_instructions button{
margin-top: 10px;
width: 275px;
}

.form_instructions p{
font-size: 16pt;
}

.form_container{
width: 60%;
margin: auto;
margin-top: 20px;
border: 2px solid #999;
padding: 5px;
display:none;
}

.form_container .field{
width: 70%;
margin: auto;
}

0 comments on commit c9706ac

Please sign in to comment.