Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set my rails app up so that I can click a letter and see only the entries starting with that letter?
    primarykey
    data
    text
    <p>My rails app basically displays a dictionary of sorts, which is stored in a database. I've set up a basic rails app with scaffold to display this on a webpage, but I can't for the life of me figure out how to set this next bit up. Basically I want a row of the 26 alphabetical letters, and when you click on a letter (say 'A'), I only want to see the dictionary entries of that letter. </p> <p>My index.html.erb file:</p> <pre><code>&lt;% for char in 'A'..'Z' %&gt; &lt;%= link_to( "#{char}", "/words/lettersearch", :id =&gt; "#{char}") %&gt; &lt;% end %&gt; </code></pre> <p>my words_controller.rb file method for doing this:</p> <pre><code>def lettersearch @word = Word.find(:all, :conditions =&gt; ["word LIKE ?", "#{params[:word]}%"]) end </code></pre> <p>It then outputs the @word to another page.</p> <p>My problem is that it just outputs the entire dictionary again, no matter what letter I click on the index page. I know it's to do with the routing, as it never seems to actually run the 'lettersearch' method - it's always trying to run through the 'Show' method that's defined by default earlier in the controller.</p> <p>Anyone able to give me a quick hand with how to route this thing through? I'm pretty new to rails and I don't understand the workings of link_to very well at all.</p> <p>routes.rb:</p> <pre><code>Dictionary::Application.routes.draw do resources :words do post 'search', :on =&gt; :collection post 'lettersearch', :on =&gt; :collection end #Rest of routes.rb still commented apart from match ':controller(/:action(/:id))(.:format)' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload