ga-dc / wdi5-project3

Project 3
0 stars 5 forks source link

form helper hidden_field #58

Closed hharper closed 9 years ago

hharper commented 9 years ago

I have a 'save to favorites' form that takes displayed search results and saves its name to my 'favorites' database, but now I wanted to add more parameters to the hidden_field form (not just name but also url, rating, address, etc.). How do I do that in the form? Code below:

<div class="search-result">
        <h1><a href="<%= @brunch.url %>"> <%= @brunch.name %> </a></h1>
        <%= @brunch.rating_img_url_large %>">

        <%= @brunch.review_count %> reviews

            <%= @brunch.location.display_address[0] %>

           <%= @brunch.location.city %>, <%= @brunch.location.state_code %> <%= @brunch.location.postal_code %>

          <%= @brunch.display_phone %>

    <%= form_for @favorite do |fav| %>
               <%= fav.hidden_field(:name) %>
    <%= submit_tag 'Save to Favorites', data: { confirm: "Saved to Favorites! Go to My Favorites to see your Favorite Brunch Spots"}, :class => "favoriteBtn" %>
    <% end %>
</div>

thanks!

RobertAKARobin commented 9 years ago

The same way you add fields to any form:

<%= fav.text_field(:rating) %>
<%= fav.text_area(:url) %>

Maybe I'm misunderstanding the question?

jrhorn424 commented 9 years ago

I would also examine where you are getting your hidden data from? Hidden fields are usually used to transfer data across page interactions. However, in rails we have access to session store. More likely, we have access to either a ruby object in memory on the server, or a javascript object in memory on the client, that has the data we need.

How is the hidden field for name being populated?

andrewsunglaekim commented 9 years ago

I think we solved this issue when I was at the genius bar, I'm going to close it for now, let me know if something else went wrong regarding this issue.