Dictionary show action for letters, alphabetical links helper
This commit is contained in:
@@ -3,4 +3,9 @@ class DictionaryController < ApplicationController
|
||||
@parts_of_speech = PartOfSpeech.all
|
||||
@words = Word.all
|
||||
end
|
||||
|
||||
def show
|
||||
@letter = params[:id]
|
||||
@words = Word.where('substr(word, 1, 1) = ?', @letter)
|
||||
end
|
||||
end
|
||||
|
@@ -1,2 +1,10 @@
|
||||
module DictionaryHelper
|
||||
LETTERS = ['i', 'u', 'e', 'o', 'a', 'm', 'n', 'p', 't', 'k', 's', 'w', 'l', 'j'].sort
|
||||
|
||||
def alphabetical_links
|
||||
|
||||
LETTERS.map do |l|
|
||||
link_to l.to_s, dictionary_path(l)
|
||||
end.join("\n")
|
||||
end
|
||||
end
|
||||
|
@@ -1,6 +1,8 @@
|
||||
<h1>Dictionary#index</h1>
|
||||
<p>Find me in app/views/dictionary/index.html.erb</p>
|
||||
|
||||
<%= sanitize alphabetical_links, tags: ["a"] %>
|
||||
|
||||
<p><%= @parts_of_speech.count %> parts of speech entries in database</p>
|
||||
<h1>Parts of Speech</h1>
|
||||
<table>
|
||||
|
9
app/views/dictionary/show.html.erb
Normal file
9
app/views/dictionary/show.html.erb
Normal file
@@ -0,0 +1,9 @@
|
||||
<div>
|
||||
<%= @letter.to_s %>
|
||||
</div>
|
||||
|
||||
<% @words.each do |word| %>
|
||||
<div>
|
||||
<h1><%= word.word %></h1>
|
||||
</div>
|
||||
<% end %>
|
Reference in New Issue
Block a user