Is it possible to pass Params in render partial?

I am using the jQuery UI slider to dynamically update items on a page. How can I let the controller receive the values from the slider? Is it possible to pass such information through as a local? If so, how would the local be handled by the partial

I am currently updating the whole page and using the where clause with the params. @articles = Article.where(:year => params[start_year]...params[start_year])

I would like to just using jquery to empty this section and render a new collection of partials using the values set by the slider. Is there a best practice for this?

Answers


I think the best option would be make an ajax call to a controller and pass in the paramaters through that.

Then, with the returned information, you should repopulate the parts of the page that need to be repopulated.

In your routes, you'll want something like this:

get "article/between_years", :controller=>"article", :action=>"between_years"

and in your controller, you'll have the function

def between_years
  @articles = Article.where(:year => params[start_year]...params[start_year])
  render :layout=>false ### this line makes it so the application.haml (or html.erb) is not rendered along with your code)
end

and in the directory app > views > articles, you'll have the haml, or erb file with the html you'll be wanting to add in.

then your jquery will look something like this:

$.get("/article/between_years",{start_year:1991,end_year:2011},function(data, status, xhr){  /// does ajax call to the article route we set up above /
  ..
  $("body").append(data);  ///appends the html data returned to the body
                           ///you will probably want to change this a bit
                           ///so every thing is added to the proper place
  ...
});

I wrote another answer a little while ago that outlined a simular work flow, you may want to take a look at that => Auto populate text_fields based on selected item from another collection_select in Rails 3


Need Your Help

Entity Framework - Connection string - Keyword not supported 'Data Source'

asp.net-mvc-3 entity-framework-4 connection-string

I know this is a common issue faced by beginners in EF and there have been multiple questions and answers on the same here, but still I have not been able to still resolve the issue.

Syntax error of ''?

mysql stored-functions

I can't seem to figure out where this is coming from... MySQL give me a syntax error of an empty quote and gives me a line number that doesn't seem to be wrong at all. Worse still, deleting the loo...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.