ga-wdi-exercises / project2

[project]
1 stars 30 forks source link

Issue - Search picture-tag on index page #917

Closed dionadk closed 6 years ago

dionadk commented 6 years ago

I am trying to add a search button on the index page. User can type in the tag names and hit search. how do I get the search parameter value so that i can check for all pics with the tag name? pics index views -

<%= form_tag(pics_path,method: :get) do %>
  <%= text_field_tag :name,params[:name]%>
  <%= submit_tag 'Search',name: nil %>
<% end %>

To search for the tag name

<div class="flexcollection">
  <% @tags.where(:name => "design").each do |tag| # ******** instead of design need to pass the search parameter value******** %>
  <% @pics.where(:id => tag.pic_id).each do |pic|%>
      <div class="flexImg">
        <img class="pic" src="<%= pic.img_url %>"/>
        <%= link_to pic.title,pic_path(pic)%>
      </div>
  <%end%>
<%end%>

link to my github repo: https://github.com/dionadk/Wexels

superbuggy commented 6 years ago

I think what you need is another request-response cycle.

Check out http://railscasts.com/episodes/37-simple-search-form/

superbuggy commented 6 years ago

just kidding you already have that with your form! params[:name] instead of "design".

superbuggy commented 6 years ago

closing for now!