This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scratch.txt
77 lines (59 loc) · 2.46 KB
/
scratch.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
Parameters: {"utf8"=>"✓", "authenticity_token"=>"9RAXaCWrq3XN2Bpy0pYk4dRfjODzRx0zYeR5SCmkoCcZzlId+9GRQs7lck01QvQ9npyGVTVJPgql8BEclOAGAw==",
"ship"=>
{"name"=>"delete this ship",
"type_class"=>"",
"warp_factor"=>"6",
"complement"=>"",
"note"=>"no crew yet!",
"assignments_attributes"=>
{"0"=>
{"crew_id"=>"",
"ship_id"=>"",
"name"=>"",
"description"=>""}}},
"commit"=>"Create Ship"}
ship[assignments_attributes][crew_id]
# previous select menu on new ship form
<%= a.select(:crew_id) do %>
<%= options_from_collection_for_select(Crew.all, :id, :name) %>
<% end %></p>
'params[:ship][:assignments_attributes][:crew_id]'
<% if 'params[:ship][:assignments_attributes][:crew_id]' %>
<% end %>
Checkboxes:
<%= f.collection_check_boxes :crew_id, Crew.all, :id, :name %><br>
or
<div class="field">
<%= hidden_field_tag "ship[crew_ids][]", nil %>
<% Crew.all.each do |crew| %>
<%= check_box_tag "ship[crew_ids][]", crew.id, @ship.crew_ids.include?(crew.id), id: dom_id(crew) %>
<%= label_tag dom_id(crew), crew.name %> <br>
<% end %>
</div>
// from ship.js
```js
shipLi.innerHTML = 'Name: <a href="/ships/' + ship.id + '">' + ship.name + '</a>, Class: ' + ship.typeClass + ', Warp Factor: ' + ship.warpFactor;
```
shipLi.innerHTML = 'Name: <a id="'+ ship.id + '" href="#" onclick="getShipInfo();">' + ship.name + '</a>, Class: ' + ship.typeClass + ', Warp Factor: ' + ship.warpFactor;
/ships/' + ship.id + ' **Put in place of the # in getShipInfo();
//= require jquery
//= require jquery_ujs
//= require turbolinks
*** Adding the Alphabetize function***
let alphaButton = document.createElement("button");
alphaButton.innerHTML = '<button onclick="alphabetize();">Alphabetize Ships</button>';
shipList.append(alphaButton);
// right after making new Ship
let allShips = [];
allShips.push(ship);
function alphabetize() {
let shipList = document.getElementById("shipList");
shipList.innerText = ""; // clear out the current list
allShips.sort(function(a, b) {
return a.name > b.name;
}).forEach(function(ship) {
let shipLi = document.createElement("li");
shipLi.innerHTML = 'Name: <a href="#" onclick="getShipInfo(' + ship.id + ');">' + ship.name + '</a>, Class: ' + ship.typeClass + ', Warp Factor: ' + ship.warpFactor + '<br> <div id="moreInfoSpot"></div>';
document.getElementById("shipList").appendChild(shipLi);
});
};