Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/pet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ def first_name
def full_name
first_name + " " + last_name
end

def expression_id
3 # lacking a model for now, default to the higest possible ID
end

def lucky_number
binary_string = ("%05b" % color_id) + ("%03b" % shape_id) + ("%02b" % expression_id)
binary_string.to_i(2)
end
end
10 changes: 5 additions & 5 deletions app/views/pets/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
<% end %>

<% @colors.each do |color| %>
<input type="radio" value="<%= color.id %>" name="color[color_id]" id="color_color_id_<%= color.id %>"/>
<label style="background-color:#<%= color.hex_value %>" for="color_color_id_<%= color.id %>"><%= color.hex_value %></label>
<input type="radio" value="<%= color.id %>" name="pet[color_id]" id="pet_color_id_<%= color.id %>"/>
<label style="background-color:#<%= color.hex_value %>" for="pet_color_id_<%= color.id %>"><%= color.hex_value %></label>
<% end %>
<br>
<% @shapes.each do |shape| %>
<input type="radio" value="<%= shape.id %>" name="shape[shape_id]" id="shape_shape_id_<%= shape.id %>" />
<label for="shape_shape_id_<%= shape.id %>"><%= image_tag(shape.image)%></label>
<input type="radio" value="<%= shape.id %>" name="pet[shape_id]" id="pet_shape_id_<%= shape.id %>" />
<label for="pet_shape_id_<%= shape.id %>"><%= image_tag(shape.image)%></label>
<% end %>
<br>

<div class="field">
<%= f.label :last_name %><br>
<%= f.text_field :last_name %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/pets/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<th>Color</th>
<th>Shape</th>
<th>Name</th>
<th>Lucky Number</th>
<th colspan="3"></th>
</tr>
</thead>
Expand All @@ -18,6 +19,7 @@
<td bgcolor="#<%= pet.color.hex_value %>"></td>
<td bgcolor="#<%= pet.color.hex_value %>"><%= image_tag(pet.shape.image)%></td>
<td><%= pet.full_name %></td>
<td><%= pet.lucky_number %></td>
<td><%= link_to 'Show', pet %></td>
<td><%= link_to 'Edit', edit_pet_path(pet) %></td>
<td><%= link_to 'Destroy', pet, method: :delete, data: { confirm: 'Are you sure?' } %></td>
Expand Down