整理一些非常有用的gems

来源:互联网 发布:斯米兰岛和普吉岛 知乎 编辑:程序博客网 时间:2024/06/05 09:54
  1. will_paginate
    URL:
    Fuction: 
    Install:
    Use:
    代码如下:


  2. open_flash_chart
    URL: https://github.com/pullmonkey/open_flash_chart
    DEMO:http://pullmonkey.com/projects/open_flash_chart2/
    Fuction: 能非常的开发出各种漂亮,强大的图表
    code:
    class TestItController < ApplicationController    #柱状图  def index    actionname = params[:actionname] || "index"    Rails.logger.info("actionname is #{actionname}")    respond_to do |wants|      wants.html {        @graph = open_flash_chart_object( 600, 300, url_for( :action => actionname, :format => :json ) )      }      wants.json {         chart = OpenFlashChart.new("我的柱状图") do |c|          c << BarGlass.new( :values => (1..10).sort_by{rand} )        end        render :text => chart, :layout => false      }    end  end  #饼状图  def bar   respond_to do |format|     format.json{       title = Title.new("Pie Chart Example For Chipster")       pie = Pie.new       pie.start_angle = 35       pie.animate = true       pie.tooltip = '#val# of #total#<br>#percent# of 100%'       pie.colours = ["#d01f3c", "#356aa0", "#C79810"]       pie.values  = [2,3, PieValue.new(6.5,"Hello (6.5)")]       chart = OpenFlashChart.new       chart.title = title       chart.add_element(pie)       chart.x_axis = nil       render :text => chart.to_s     }   end  end  #line   def line    title = Title.new("Multiple Lines")    data1 = []    data2 = []    data3 = []    10.times do |x|      data1 << rand(5) + 1      data2 << rand(6) + 7      data3 << rand(5) + 14    end    line_dot = LineDot.new    line_dot.text = "Line Dot"    line_dot.width = 4    line_dot.colour = '#DFC329'    line_dot.dot_size = 5    line_dot.values = data1    Rails.logger.info("line_hollow data is : #{line_dot.inspect}")    line_hollow = LineHollow.new    line_hollow.text = "Line Hollow"    line_hollow.width = 1    line_hollow.colour = '#6363AC'    line_hollow.dot_size = 5    line_hollow.values = data2    Rails.logger.info("line_hollow data is : #{line_hollow.inspect}")    line = Line.new    line.text = "Line"    line.width = 1    line.colour = '#5E4725'    line.dot_size = 5    line.values = data3    Rails.logger.info("line data is : #{line.inspect}")        y = YAxis.new    y.set_range(0,20,5)    x_legend = XLegend.new("MY X Legend")    x_legend.set_style('{font-size: 20px; color: #778877}')    y_legend = YLegend.new("MY Y Legend")    y_legend.set_style('{font-size: 20px; color: #770077}')    chart =OpenFlashChart.new    chart.set_title(title)    chart.set_x_legend(x_legend)    chart.set_y_legend(y_legend)    chart.y_axis = y    chart.add_element(line_dot)    chart.add_element(line_hollow)    chart.add_element(line)    respond_to do |format|      format.json {        render :text => chart.to_s      }    end  end  #波动图  def chart    data1 = []    data2 = []    year = Time.now.year    31.times do |i|      x = "#{year}-1-#{i+1}".to_time.to_i      y = (Math.sin(i+1) * 2.5) + 10      data1 << ScatterValue.new(x,y)      data2 << (Math.cos(i+1) * 1.9) + 4    end    dot = HollowDot.new    dot.size = 3    dot.halo_size = 2    dot.tooltip = "#date:d M y#<br>Value: #val#"    line = ScatterLine.new("#DB1750", 3)    line.values = data1    line.default_dot_style = dot    x = XAxis.new    x.set_range("#{year}-1-1".to_time.to_i, "#{year}-1-31".to_time.to_i)    x.steps = 86400    labels = XAxisLabels.new    labels.text = "#date: Y-M-d#"    labels.steps = 86400    labels.visible_steps = 2    labels.rotate = 90    x.labels = labels    y = YAxis.new    y.set_range(0,15,5)    chart = OpenFlashChart.new    title = Title.new(data2.size)    chart.title = title    chart.add_element(line)    chart.x_axis = x    chart.y_axis = y    respond_to do |format|      format.json {        render :text => chart.to_s      }    end  endend
    line图还有一些问题,需要研究一下
    访问方法
    http://192.168.1.21/test_it?actionname=%22bar%22

  3. cache_money
    URL:https://github.com/nkallen/cache-money
  4. auto_complete
    URL:https://github.com/edendevelopment/auto_complete
  5. 二维码生车插件
    http://code.google.com/p/qrcode-rails/