will paginate in rails 3 - ruby-on-rails

I'm upgrading my rails 2.3.8 app to rails 3.0.1 while using will_paginate in one module
for example:
<%= will_paginate #sample , :renderer => 'RemoteLinkRenderer' , :remote => {:loading => 'loadingPanel.show()',:complete => 'loadingPanel.hide()' } %>
This code isn't working.
Any ideas are greatly appreciated

I don't want to look rude but "This code doesn't working" isn't enough to be helped. You should provide more informations about your problem :)

You are not simply using will paginate. Apparently, you are also using this patch, and it is not working with Rails 3.
You should edit the question and update it's title to somthing like "remote pagination via Ajax with will_paginate and rails 3".
There is one html5-based solution described here
To convert this solution into non-html5 you may maybe do something like this(*):
$$('.pagination a').each(function(e){
var link=e.getAttribute('href');
e.setAttribute(
'onclick',
'new Ajax.Request(\'' + link + '\', {asynchronous:true, evalScripts:true})');
e.writeAttribute('href',null);
}
* has to be trimmed if there are multiple paginations...

Related

link_to_function in rails 3.1 with blocks throws wrong number of arguments error

I recently started working with rails 3. I'm trying to add a multi-modal form into my application. I'm following the steps mentioned at Handle multiple models in one form
When I try to add a link via following helper function, I get
wrong number of arguments (1 for 2)
Code block below.
def add_task_link(name)
link_to_function name do |page|
page.insert_html :bottom, :tasks, :partial => 'task' , :object => Task.new
end
en
Googling for solution didn't take me anywhere.
Thank you.
You should find another tutorial, RJS and prototype are deprecated in rails 3, they've been replaced with jQuery.
If you really insist on going forward, you can bring RJS and prototype back by adding the following to your Gemfile:
gem 'prototype-rails'
This will bring back the correct version of link_to_function.

Using reCaptcha with Rails 2.3.12

So I'm trying to get reCaptcha to render on a partial form view that uses HAML. I have tried using the :ruby filter and then adding <%= recaptcha_tags %> but that didn't work, neither has anything else that I've found. Is there a way to implement this?
*Revision
Ahem, more specifically, can anyone tell me what I need to have for the <%= recaptcha_tags %> helper? Every thing I find on this subject just says "Add <%= recaptcha_tags %> wherever you want it to appear!" and absolutely nothing on what the helper should contain.
*Another Revision
I am indeed trying to use Ambethia. I tried using just = recaptcha_tags but that didn't work, I got an error saying it was an undefined variable or method. I installed the Ambethia/reCaptcha as a plugin using script/plugin install git://github.com/ambethia/recaptcha.git and I put config.gem "ambethia-recaptcha", :lib => "recaptcha/rails", :source => "http://gems.github.com" in environment.rb along with my public/private keys.
*Started Over
Okay, got rid of everything I had done initially. Can anyone help me with this? I follow all of the tutorials I can find on it, but none of them explain how to implement/create the helpers for <%= recaptcha_tags %> or <%= verify_recaptcha %>. I'm obviously new to RoR and implementing reCaptcha of any kind, so I'm sorry I'm asking for my hand to be held but I am honestly lost and am not finding any guidance anywhere! Thanks so much anyone and everyone.
did you try simply:
= recaptcha_tags
You don't mention the plugin you're using. I'm assuming this one. If that's the case, the recaptcha_tags helper will return the HTML for the captcha, and you'd insert it into whichever forms you wanted the captcha to appear on.
The <%= %> around recaptcha_helper aren't part of the helper, but rather the way you insert content into erb templates (and other templating languages resembling erb). In Haml you don't need the surrounding tag. It's just =.
I had the same problem and I finally solved it realizing that my form was called asynchronously.
I added:
= recaptcha_tags :ajax => true
and captcha appeared.
Hope this could help the original question.

Rails pagination of subset of a class

I have a rails app and I'm trying to set up pagination for a view of the Essays class. I'm new to rails... so I can do this for ALL of them, but I only want certain ones to be in this list (where all the essays are contained in Essay.find(Ranking.where(:user_id=>current_user.id).essay_id)).
home.html.erb contains (among other things):
`<%= will_paginate #essays%>
<ul class="users">
<%= render #essays %>
</ul>
<%= will_paginate #essays%>`
in the Pages Controller:
def home
#...
#essays = Essay.paginate(:page => params[:page])
end
I tried adding #essays=Essay.find(Ranking.where(:user_id=>current_user.id).essay_id) before the #essays=Essay.paginate(:page => params[:page]) but the method essay_id for the Ranking class is not available here. How do I get around this? Thanks!
This should work:
Essay.joins(:rankings)
.where(:rankings => {:user_id => current_user.id})
.paginate(:page => params[:page])
While this can be done with will_paginate. I've had some issues with this plugin for Rails 3. A much smoother solution, in my opinion, was to use another pagination plugin called Kaminari.
Assuming, essay_id is passed as a param, you could try:
#ranking = Ranking.where(:user_id => current_user.id, :essay_id => params[:essay_id]).page(params[:page]).per(10)
Or depending on your logic. If the essay object has already been identified in your controller:
#essay = Essay.find(1234)
#ranking = Ranking.where(:user_id => current_user.id, :essay_id => #essay.id).page(params[:page]).per(10)
And then, in your view:
<%= paginate #ranking %>
Even better, to get you started on Kaminari, you can view this rails cast. As noted from the rails cast:
The first-choice gem for pagination in
Rails is will_paginate, but the
currently released version doesn’t
support Rails 3. There is a
pre-release version available that
works but it hasn’t been updated for
several months. If will_paginate is no
longer in active development are there
any other gems we could use?
One alternative is Kaminari. This
seems to provide a cleaner
implementation of pagination and
offers several improved features, too,
so let’s try it in our application
instead.
Hope that helps!
Simply chain paginate method after find method:
#essays=Essay.find(Ranking.where(:user_id=>current_user.id).essay_id).paginate(:page => params[:page])

Best way to handle ajax upload?

form_for #model, :remote => true, :html => {:multipart => true } does not allow us to send file via ajax.
I have found this but it's not up to date and it relies on dependancies :
http://khamsouk.souvanlasy.com/articles/ajax-file-uploads-in-rails-using-attachment_fu-and-responds_to_parent
http://www.williambharding.com/blog/rails/rails-ajax-image-uploading-made-simple-with-jquery/
Anyone with up to date ressources ?
This is example for uploading File on Rails 3 using Jquery.
Make use of it, it is simple
https://github.com/blueimp/jQuery-File-Upload/wiki/jQuery-File-Upload-for-Rails-3
I've used Uploadify in a recent application http://www.uploadify.com/ Some Rails specific notes here http://railstips.org/blog/archives/2009/07/21/uploadify-and-rails23/ I know you said Rails 3, but the concepts are the same.

Rails 2 to Rails 3 : using link_to instead of link_to_remote (including remote and update)

A quick and easy answer I'm sure.
I'm upgrading a Rails project from version 2 to version 3 and replacing a load of the link_to_remote with link_to's as per the Rails 3 update. Even something as simple as :
<%= link_to "Check Time",
{:action=>:get_time}, :remote=>true, :update=>'current_time' %>
<div id='current_time'></div>
doesn't seem to work. The request (using get method) is going through ok and the rendered html is :
Check Time
Routes.rb entry :
get "monitoring/get_time"
As I say I'm sure this is a very obvious issue on my part!
The :update option isn't supported by the new link_to :remote => true.
You will either have to
use the legacy plugin
write the JS/AJAX yourself instead of using :remote => true
use render :update { |page| p.replace_html ... }
The :update parameter is gone. You need to handle the DOM update yourself using Unobtrusive JavaScript. Also, make sure you actually included the csrf_meta_tag helper in your layout.
I wrote an article about using unobtrusive JavaScript in Rails 3.

Resources