Skip to main content

Trigger a form submit on a different page - Rails 3



So, I have a form on page 'A' which lets users type in the name of a band and see album covers and prices, courtesy of the Amazon API.







<%= form_tag(amazon_path, :method => 'get') do %>

<h3> Search for Albums </h3>

<%= label_tag(:amazon_search_form, "by Band/Artist:") %>

<%= text_field_tag(:amazon_search_form) %>

<%= submit_tag("Search") %>

<% end %>







Users can also see all bands they are following on their profile page. From their profile page, they are able to select a band 'b' (perhaps by clicking on the band's img). After that, if they click on the link to go to page 'A', I would like the form to be automatically submitted with band 'b's name so that the user won't have to type in the name of band 'b' to see the albums for band 'b'.





I can't tell if jQuery's .submit function can pass a parameter of the band's name to the form when the user navigates to page 'A'. The other problem is that the form is on another page which confounds me. I'm not even sure where to look for the answer. Is there a solution within Rails 3 to this problem?





Any tips would help me. Thank you!


Comments

  1. Unless there is an unspecified reason not to, I would just make the link carry the band name from its profile page.

    So something like:

    <%= link_to "Nirvana", amazon_path(:amazon_search_form => "Nirvana") %>


    This should hit your amazon_path endpoint with the search term and render your template with the albums

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.