I'm trying to set up a view with infinite scroll. I'm doing that by having javascript load a partial, but the problem is I need to pass in the variable @row (see the partial below) to calculate which objects to load.
The @row variable doesn't load when the partial is inserted via the js below.
Am I approaching this problem wrong (is there an easier way to insert rails objects), or is there a way to pass the @row variable into the partial from js.
Controller:
respond_to do |format|
format.html
format.js
end
The js loaded from the controller response above:
$(' #{render "shared/browse_row" ).insertAfter( $('.row') );
View:
-(1..6).each do
= render "shared/browse_row"
browse_row partial:
.row{'data-row'=> "#{@row}"}
-@row += 1
%ul
-@i = 0
-project_row( @row ).each do |project|
-@i += 1
-@i == 4 ? right = "right" : right = ""
%li{:class => right}
= image_tag( project.display_pic.url(:medium) )
.filler{'data-link' => '/projects/'+project.id.to_s }
.filler-text
.p-name
= project.name
.p-creator= "by " + project.creator.name
.p-price= "$" + number_with_precision(project.price, :precision => 2).to_s
.p-days
- if days_left( project ) > 0
="Expires in " + pluralize( days_left( project ), " Day")
- else
="Expires Today"
.p-percent
- percent_funded(project).gsub("%","").to_i > 100 ? percent = "100%" : percent = percent_funded(project)
.p-percent-bar{:style => "width:#{ percent };"}