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 <&开发者_运维百科lt; "#{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
autocomplete_for_grant_name
and auto_complete_for_grant_name
spell autocomplete differently.
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
精彩评论