Ruby on Rails
Monday, December 10, 2012
Hope it is o.k. when I post a js/ ajax related to rails.. question here.
I have a form with a select field.
What I have in mind is to display an inline div with some db related infos when the select_field has changed.
form
<%= f.collection_select :parent_id, Project.all, :id, :project_name, :include_blank => 'Part Project ?' %>
<div id="mydiv" style="display:none"></div>
js
$(document).ready(function() {
$("select#project_parent_id").bind("change",function() {
var id = $(this).children(":selected").val();
var params = 'find_id=' + id;
$.ajax({
type: 'get',
url: "find_project",
data: params,
success : function(data) {
$("div#mydiv").show();
$("div#mydiv").html(data.name)
}
})
})
})
controller
def find_project
@project = Project.find(params[:find_id])
end
result..in console GET http://0.0.0.0:3000/projects/find_project?find_id=1 404 (Not Found)
Some help would be great..
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/QeaTeL_FItMJ.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment