1 2 3 4 5 6 7 8 9 10 11 12 | class RecipesController < ApplicationController ... def index end def search_ajax @recipes = Recipe.find( :all, :conditions => [ "name LIKE ?", "%#{params[:recipe][:name]}%" ] ) render :layout=>false end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <html> <head> <%= javascript_include_tag :defaults %> </head> <body> <%= form_tag nil, { :id => 'search_form' } %> <%= text_field 'recipe', 'name' %> <%= end_form_tag %> <div id="recipe"> </div> <%= observe_form :search_form, :frequency => 0.5, :update => 'recipe', :url => { :action => 'search_ajax' } %> </body> </html> |
1 2 3 4 | <% @recipes.each { |r| %> <h1><%= r.name %></h1> <p><%= r.description %></p> <% } %> |
1 2 3 4 5 6 7 8 | <% @recipes.each { |r| %> <h1><%= r.name %></h1> <p><%= r.description %></p> <div id="extra_<%= r.id %>"></div> <%= link_to_remote 'Extra', :url => { :action => 'get_extra_ajax', :id => r.id }, :update => "extra_#{r.id}" %> <% } %> |
1 2 3 4 5 6 7 | class RecipesController < ApplicationController ... def get_extra_ajax @recipe = Recipe.find( params[:id] ) render :layout=>false end end |
1 2 | <blockquote><%= simple_format @recipe.ingredients %></blockquote> <p><%= simple_format @recipe.instructions %></p> |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |