In Rails, Search, index and edit all in the same page
I´m using Rails 3, and my default page setup will have开发者_高级运维: 1. A search form 2. A list with the results 3. A edit form, that will present the selected item from the list.
I don´t know how to do this without loosing my search params. Probably I have to pass my search params again when I select an item, but, how?
After all, what´s the best way to put all this in the same page ?
Search form submits to index
via AJAX. index
sends down js.erb to load your partial. Selecting an item calls edit
via AJAX. edit
sends down js.erb to load your edit
form. Am I missing something?
If you want to do it without ajax, you can store search params in session:
session[:search_params] = "some value"
Still having problems when submitting the form to update action. No update action is called in the controller. I get this erro in log:
ActionController::RoutingError (No route matches "/cids"):
this is my main index page:
<div id="page-content">
<%= render "search_form" %>
<%= render "search_grid" %>
<%= render "form" %>
</div>
this is the link to show edit form:
<td><%= link_to '', edit_cid_path(cid), :remote=>true %></td>
this is the edit.js.erb file:
$("#edit-form").html("<%= escape_javascript(render("form")) %>")
this is the begin of my _form partial:
<div id="edit-form">
<% if @cid %>
<%= form_for(@cid, :html => {:method => "put", :id=>"update-form"}) do |f| %>
<% if @cid.errors.any? %>
and this is the application.js code:
$("#edit-form").submit(function(){
saveElement($(this).find("form"));
return false;
});
function saveElement(obj)
{
$.post(obj.action, $(obj).serialize(),
function(){refreshCss()},
"script");
}
精彩评论