kfquinn
kfquinn

Reputation: 1

Rails3 Module Help

So I'm currently trying to upgrade from 2.3 -> 3, and I'm running into an issue. In rails 2.3 I had a module that was comprised of autocomplete methods. So on key press an ajax request would be sent to the corresponding message. For example:

/grants/auto_complete_for_grant_name

module AutoComplete

 def auto_complete_for_grant_name
  name = params[:grant][:name].downcase  
  @grants = Grant.find(:all, :limit => 10, :conditions => "name like '%"+name+"%'")
  render :partial => 'global/grants' 
 end
end

Once I upgraded to rails3 this is broken. I have included:

config.autoload_paths << "#{Rails.root}/lib"

in my application.rb, and:

include AutoComplete

in my application controller.

What am I doing wrong? Thanks!

Edit: (Firebug output): Failed to load source for: http://localhost:3000/grants/auto_complete_for_grant_name

Upvotes: 0

Views: 269

Answers (2)

noodl
noodl

Reputation: 17408

I don't know how to answer your actual question but I feel it's worth pointing out that :conditions => "name like '%"+name+"%'" is a huge mistake. This is prone to SQL injection attacks.

http://guides.rubyonrails.org/active_record_querying.html#conditions

Upvotes: 0

troelskn
troelskn

Reputation: 117615

autocomplete_for_grant_name and auto_complete_for_grant_name spell autocomplete differently.

Upvotes: 1

Related Questions