欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

in_place_editing使用小記

系統(tǒng) 1696 0

in_place_editing是一個用于原地編輯的ajax小控件。

典型的效果:



?首先請下載相關(guān)的rails插件,大家注意:我這里的 rails版本是2.1.2 ,所以原始的插件需要改進。

插件原始地址: http://svn.rubyonrails.org/rails/plugins/in_place_editing/

插件相關(guān)改進的討論: http://railsforum.com/viewtopic.php?id=22457

這是我根據(jù)相關(guān)的討論修改后的版本: http://qianjigui.iteye.com/upload/attachment/59164/1ddb2805-c9ce-3a9a-9d03-f950017857f4.zip

?

下面是具體的步驟:

  1. 創(chuàng)建測試應(yīng)用
            rails test
          
  2. 添加需要使用的插件
            cd test/vendor/plugins/
    ls  => in_place_editing.zip
    unzip in_place_editing.zip
          
  3. 添加一個數(shù)據(jù)表
            ruby script/generate scaffold account
          
            #需要根據(jù)自己系統(tǒng)的特點配置 config/database.yml
    #gvim db/migrate/20081212144700_create_accounts.rb
    class CreateAccounts < ActiveRecord::Migration
      def self.up
        create_table :accounts do |t|
          t.column :name, :string
          t.column :id_card, :string
          t.column :email, :string
          t.timestamps
        end
      end
    
      def self.down
        drop_table :accounts
      end
    end
    
          
    ?
            # MySQL.  Versions 4.1 and 5.0 are recommended.
    #
    # Install the MySQL driver:
    #   gem install mysql
    # On Mac OS X:
    #   sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
    # On Mac OS X Leopard:
    #   sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
    #       This sets the ARCHFLAGS environment variable to your native architecture
    # On Windows:
    #   gem install mysql
    #       Choose the win32 build.
    #       Install MySQL and put its /bin directory on your path.
    #
    # And be sure to use new-style password hashing:
    #   http://dev.mysql.com/doc/refman/5.0/en/old-client.html
    development:
      adapter: mysql
      encoding: utf8
      database: test_development
      username: testmysql
      password: ******
      host: localhost
      socket: /var/run/mysqld/mysqld.sock
      
    # Warning: The database defined as "test" will be erased and
    # re-generated from your development database when you run "rake".
    # Do not set this db to the same as development or production.
    test:
      adapter: mysql
      encoding: utf8
      database: test_test
      username: testmysql
      password: ******
      host: localhost
    
    production:
      adapter: mysql
      encoding: utf8
      database: test_production
      username: testmysql
      password: ******
      host: localhost
          
    ?運行rake
            rake db:migrate
          
  4. 下面我們在做了基礎(chǔ)設(shè)施后,開始我們的具體使用吧:
            #插入必要的javascript到layout(app/views/layouts/accounts.html.erb )中
    <%= javascript_include_tag :defaults %>
    
    #得到完整的文件
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
      <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
      <title>Accounts: <%= controller.action_name %></title>
      <%= stylesheet_link_tag 'scaffold' %>
      <%= javascript_include_tag :defaults %>  
    </head>
    <body>
    
    <p style="color: green"><%= flash[:notice] %></p>
    
    <%= yield  %>
    
    </body>
    </html>
    
          
    ?
  5. 閱讀插件的README我們了解到,需要給使用這個插件的Controller添加相應(yīng)的配置方法
    README 寫道
    Example:

    # Controller
    class BlogController < ApplicationController
    in_place_edit_for :post, :title
    end

    # View
    <%= in_place_editor_field :post, 'title' %>
    ?下面我們在app/controllers/accounts_controller.rb中添加需要的方法,在這里我們希望每一個字段都具有這樣的特性。
            class AccountsController < ApplicationController
      Account.content_columns.each do |c|
        in_place_edit_for :account, c.name
      end
      
      # GET /accounts
      # GET /accounts.xml
      def index
        @accounts = Account.find(:all)
    
        respond_to do |format|
          format.html # index.html.erb
          format.xml  { render :xml => @accounts }
        end
      end
    
      # GET /accounts/1
      # GET /accounts/1.xml
      def show
        @account = Account.find(params[:id])
    
        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml => @account }
        end
      end
    
      # GET /accounts/new
      # GET /accounts/new.xml
      def new
        @account = Account.new
    
        respond_to do |format|
          format.html # new.html.erb
          format.xml  { render :xml => @account }
        end
      end
    
      # GET /accounts/1/edit
      def edit
        @account = Account.find(params[:id])
      end
    
      # POST /accounts
      # POST /accounts.xml
      def create
        @account = Account.new(params[:account])
    
        respond_to do |format|
          if @account.save
            flash[:notice] = 'Account was successfully created.'
            format.html { redirect_to(@account) }
            format.xml  { render :xml => @account, :status => :created, :location => @account }
          else
            format.html { render :action => "new" }
            format.xml  { render :xml => @account.errors, :status => :unprocessable_entity }
          end
        end
      end
    
      # PUT /accounts/1
      # PUT /accounts/1.xml
      def update
        @account = Account.find(params[:id])
    
        respond_to do |format|
          if @account.update_attributes(params[:account])
            flash[:notice] = 'Account was successfully updated.'
            format.html { redirect_to(@account) }
            format.xml  { head :ok }
          else
            format.html { render :action => "edit" }
            format.xml  { render :xml => @account.errors, :status => :unprocessable_entity }
          end
        end
      end
    
      # DELETE /accounts/1
      # DELETE /accounts/1.xml
      def destroy
        @account = Account.find(params[:id])
        @account.destroy
    
        respond_to do |format|
          format.html { redirect_to(accounts_url) }
          format.xml  { head :ok }
        end
      end
    end
    
          
    ?其中我們添加了
              Account.content_columns.each do |c|
        in_place_edit_for :account, c.name
      end
          
    ?這個方法的具體作用是為每一個字段添加一個設(shè)置屬性的action,具體的定義可以參考插件中的方法描述。
  6. 在添加了相應(yīng)的響應(yīng)用的action后,我們需要讓前臺的頁面(修改app/views/accounts/show.html.erb)工作起來。
            <% for c in Account.content_columns %>
      <p>
        <b>
          <%= c.human_name %>:
        </b>
        <%= in_place_editor_field :account, c.name, {} %>
      </p>
    <% end %>
    <%= link_to 'Edit', edit_account_path(@account) %> |
    <%= link_to 'Back', accounts_path %> 
          
  7. 需要提供一個有效的表單頁面(修改app/views/accounts/new.html.erb)
            <h1>New account</h1>
    
    <% form_for(@account) do |f| %>
      <%= f.error_messages %>
      <% for column in Account.content_columns %>
        <p>
        <b><%= column.human_name %>:</b>
        <%= text_field :account, column.name %>
        </p>
      <% end %>
      <p>
        <%= f.submit "Create" %>
      </p>
    <% end %>
    
    <%= link_to 'Back', accounts_path %>
    
          
  8. 讓我們跑起來看看效果吧。
            ruby script/server
          
    ?在瀏覽器中輸入http://localhost:3000/accounts
  9. 按照步驟,我們點擊? New account。輸入相關(guān)數(shù)據(jù)
  10. 點擊show.體驗效果吧。

    ?

    ?

in_place_editing使用小記


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲精品在线免费观看视频 | 免费国产自久久久久三四区久久 | 国产精品久久婷婷六月丁香 | 色色色五的天 | 日韩欧美精品在线观看 | 国产精品va在线观看无 | 国产欧美日韩亚洲精品区2345 | 国产一级一级毛片 | av在线第一页 | 亚洲人成网站在线在线 | 黄色免费在线观看网址 | 亚洲精品成人av | 一级午夜a毛片免费视频 | 欧美国产激情二区三区 | 91亚洲免费 | 天天干狠狠操 | 久久伊人一区二区三区四区 | 国产成人18黄网站免费网站 | 日日爱669| 久久极品 | 2020天天狠天天透天干天天怕 | 成人亚洲一区 | 成在线人免费视频 | 亚洲欧洲日本无在线码天堂 | 国产成人精品视频播放 | 久久日本精品一区二区三区 | 一级做性色a爰片久久毛片 亚洲午夜精品久久久久久app | a免费视频| 亚洲涩涩 | 欧洲亚洲精品久久久久 | 国产福利一区二区 | a久久久久一级毛片护士免费 | 色综合一区 | 精品一区二区三区免费 | 欧洲亚洲精品久久久久 | 五月激情综合网 | 12306播播影院午夜 | 天天草综合网 | 看片国产 | 久久久免费的精品 | 久久一区二区三区四区 |