Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJohn Stegman
12,182 PointsProcessing by EquipmentController#show as */*
I'm getting this response when I send a jquery get request to render the show page for a piece of equipment - or any other show page for any object in the rails app for that matter (customer, warranty, etc)
I am using a select_tag to find the id of the item in question
<%= select_tag( "equip_id", options_from_collection_for_select(@equipment, :id, :equip_id, (@equipment_id.nil?) ? nil : @equipment_id), {:class => 'equipTag'}) %>
and am seeing that the app is getting the proper id - using alert - see the code below. However, when the server responds to the request, I get
Processing by EquipmentController#show as */* **
instead of
**Processing by EquipmentController#show as HTML
which I receive if I use a link to show in a table lising of the equipment items or enter the id manually in the browser address bar - /equipment/4567 for example
javascript code -
$(document).on('change', '.equipTag', function(){
var equipId = $(this).val();
alert (equipId);
$.get('/equipment/' + equipId);
});
I'd appreciate any help. Thanks in advance. John
2 Answers
John Stegman
12,182 PointsJay, That was very helpful - thanks for the lead on the redirect.
I have adapted the code in that post to my needs and it is working. Thanks so much!
<% @custPath = {"Select"=>""} %>
<% @customers.each do |customer| %>
<% @addPath = {customer.last_name + ", " + customer.first_name => customer_path(customer.id)} %>
<% @custPath.merge!(@addPath) %>
<% end %>
<%= select_tag :show_item, options_for_select(@custPath)%>
<script type="text/javascript">
$('#show_item').change(function() {
window.location = $(this).find('option:selected').val();
});
</script>
Now I have to figure out how to make the select tag look through the selection by an input other than a single letter. In other words, if I have customers Able and Adams, when I type ad, the program goes to the first "d" customer (Davidson) not the first "ad" customer (Adams) - do you have any ideas on that?
Jay McGavren
Treehouse TeacherIt looks like you're using the jQuery get
function, which does send a request that Rails responds to. But the response goes to a jQuery handler function; it isn't loaded as the new page content. So the way things are set up now, your browser simply discards the Rails response.
What you probably want to do instead is perform a redirect by setting window.location
.
Jay McGavren
Treehouse TeacherJay McGavren
Treehouse TeacherHmm, for me, Chrome usually goes on to select subsequent letters in a dropdown as long as you don't pause too long when typing. That may be Chrome-specific, though, and it's not a very user-friendly solution regardless.
What most users would expect is probably an auto-complete field. It's a bit advanced, but here's a resource that might help.