[Rails]form_for的f.select用法

controller:

@prefecture = Prefectre.all

view:

<%= f.select :prefecture, @prefecture.collect{|p|[p.name,p.id]}.unshift([tl(‘select_please’),0]) %>

Advertisements

MySQL创建用户分配权限

mysql>CREATE USER ‘newuser’ IDENTIFIED BY ‘newpass’;

=begin

mysql>use [database_name];

mysql>GRANT USAGE ON * TO ‘newuser’ IDENTIFIED BY ‘newpass’;

mysql>GRANT SELECT,INSERT,UPDATE,DELETE ON [database_name].* TO ‘newuser’;

=end

mysql>GRANT ALL PRIVILEGES ON [database_name].* TO ‘newuser’@’[host_name]’ IDENTIFIED BY ‘newpass’;  –给指定数据库权限

mysql>GRANT ALL PRIVILEGES ON [database_name].* TO ‘newuser’@’%’ IDENTIFIED BY ‘newpass’;  –给指定数据库权限

mysql>flush privileges;

Git Server Setting

Server:
$ mkdir git
$ cd git
$ mkdir -p test.git
$ cd test.git/
$ git --bare init --shared

Client:
$ mkdir test
$ cd test
$ git init
$ git add .
$ git commit -m 'test'
$ git remote add origin ssh://(login-user)@(git-server)/home/(login-user)/git/test.git
$ git push origin master

$ git clone ssh://(login-user)@(git-server)/home/(login-user)/git/test.git

Rails国际化设置

1.在“config/initializers/”下创建“i18n.rb”文件

#encoding: utf-8

I18n.default_locale = :en

LANGUAGES = [ 

  [‘English’,’en’],

  [“Espa&ntilde;ol”.html_safe,’es’]

]

2.在“config/routes.rb”中添加如下代码

  scope ’(:locale)’ do

    resources :users

    resources :orders

    resources :line_items

    resources :carts

    resources :products do

      get :who_bouth, on: :member

    end

    root to: ‘store#index’, as: ‘store’

  end

3.在“app/controllers/application_controller.rb”中添加如下代码

  before_filter :set_i18n_locale_from_params

  # … 

  private

  def set_i18n_locale_from_params

    if params[:locale]

      if I18n.available_locales.include?(params[:locale].to_sym)

        I18n.locale = params[:locale]

      else

        flash.now[:notice]=“#{params[:locale]} translatin not available”

        logger.error flash.now[:notice]

      end

    end

  end

  def default_url_options

    { locale: I18n.locale }

  end

4.在语言文件中这样写

  layouts:

    application:

      title:     “Pragmatic Bookshelf”

5.在需要用到的视图中这样使用

<%= t(’.title’) %>

【特殊说明】在“config/application.rb”中需要注意的地方

config.i18n.default_locale = :de