`
xiayw
  • 浏览: 11618 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论

完成链接数据库 list 翻页

阅读更多
1  ActiveRecord-JDBC 已经过时了 删除
jruby -S gem remove ActiveRecord-JDBC

2  安装新的包
jruby -S gem list mysql
jruby -S gem install mysql -- --with-mysql-lib=/usr/lib/mysql --with-mysql-include=/usr/share/mysql
jruby -S gem install activerecord-jdbc-adapter
jruby -S gem remove ActiveRecord-JDBC
3  更新 gme
jruby -S gem install rubygems-update
jruby -S update_rubygems
 
sudo gem install jruby-openssl
4  开始编程
jruby -S rails shoplet
jruby script/server
jruby script/generate model ProductType
jruby script/generate model Product
jruby script/generate model ProductCategory
jruby -S rake db:migrate
jruby -S rake test:units
jruby test/unit/product_test.rb
jruby test/unit/product_test.rb
jruby -S rake db:test:load
jruby -S gem install activerecord-jdbc
jruby -S rake  db:test:load
jruby script/generate scaffold Product
jruby script/server
5  让我头痛的 翻页,老程序不中用了
jruby -S gem install will_paginate
更改 config/environment.rb

Rails::Initializer.run do |config|
  config.gem 'will_paginate', :version => '~> 2.3.14', :source => 'http://gemcutter.org'



更改 app/controller/products_controller.rb
  def list
      @products = Product.paginate  :page => params[:page], :per_page => 5
  end
  def index
    list
    render :action => 'list'
  end

update  shoplet/app/views/products/list.rhtml
 <% for product in @products %>
 
    <tr>
      <td align="left" valign="top"><%= link_to h(product.name),{:action => 'show', :id => product}, :class=>'productLink' %></td>
      <td align="right" valign="top"><%=h product.product_type.name%></td>
      <td align="right" valign="top"><%=price product %></td>
      <td>&nbsp;</td>
      <td><%= link_to 'Remove', {:action => 'destroy', :id => product}, :confirm => 'Are you sure?', :post => true %></td>
    </tr>
  <% end %>
    
</table>

 <%= will_paginate @products,:previous_label=> '上一页',:next_label=> '下一页' %> 


其实就多加了一句  <%= will_paginate @products,:previous_label=> '上一页',:next_label=> '下一页' %>

不过 不知道的时候可是折腾了我半天
提醒大家以后新rails 插件 看代码里的readme or example 比看书 好使
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics