王筝的博客
ruby学习

 

默认情况下Intellij IDEA不会提示继承了Serializable接口的类生成serialVersionUID的警告。

如果需要生成serialVersionUID,就要在Preferences里面进行设置。

如下图:Preferences -> Inspections -> Serialization issues -> Serialization class without ‘serialVersionUID’ 打上勾

 

 

然后屏蔽掉文件中关于 UID的赋值语句

 

// private static final long serialVersionUID = 1L;

 

将光标放到类名上,按atl+enter键,就会提示生成serialVersionUID了

 

 

 

然后 就能得到

private static final long serialVersionUID = 7693508705832499044L;

 

 

(1)项目导入,

点击intelliJ IDEA的Open按钮,

 

找到项目目录下pom的文件,然后点击ok (先admin, 在biz-admin, 再加dal)

 

由于之前导入过这个项目,所以现在要先删除再导入

导入后编译器的右侧就会出现Maven Projects的侧边栏按钮,点击此按钮会侧滑出相关目录,

点击上方的加号➕,继续添加其他项目

 

将其他关联项目的pom.xml文件选中,点击ok。 用同样的方式再继续导入

 

在Maven Projects面板里开启“Skip tests”Mode, 在平时开发编译过程中会节省很多时间

 

(2)按照dal biz_admin admin的依赖顺序,在Maven面板里依次双击intall,由于这是第一次运行,不需要先Clean

 

 

 

 

 

(3) Edit Configuration

 

添加一个configuration,选择Tomcat,点击Local

 

 

补充Ali-Tomcat 的安装步骤如下(使用 JDK 1.7及以上版本):
https://help.aliyun.com/document_detail/44158.html?spm=a1z2e.8101737.webpage.dtitle5.zCmGri
1.点击链接地址,下载 Ali-Tomcat,保存后解压至相应的目录(如:d:\work\tomcat)。
http://edas-public.oss-cn-hangzhou.aliyuncs.com/install_package/tomcat/taobao-tomcat-7.0.59.tgz?spm=5176.doc44158.2.2.jl2pnx&file=taobao-tomcat-7.0.59.tgz
2.点击链接地址,下载 Pandora 容器,保存后将内容解压至上述保存的 Ali-Tomcat 的 deploy 目录(d:\work\tomcat\deploy)下。
http://edas-public.oss-cn-hangzhou.aliyuncs.com/install_package/pandora/unauth/taobao-hsf.tgz?spm=5176.doc44158.2.3.jl2pnx&file=taobao-hsf.tgz

最后出来的目录结构如下所示:

d:\work\tomcat >  tree -L 2 deploy/
                 deploy/
                         └── taobao-hsf.sar
                                 ├── META-INF
                                 ├── lib
                                 ├── log.properties
                                 ├── plugins
                                 ├── sharedlib
                                 └── version.properties
补充JDK7下载地址
http://download.csdn.net/download/sxsj333/8331551

 

接着tomcat路径

 

配置JDK7

 

(4)配置Project Structure

 

 

 

 

 

 

顺便给Tomcat改个名字

 

 

 

 

 

 

 

 

 

大功告成,点击编译按钮来编译吧

 

遇到字符串编码的报错

解决方法

 

 

点击下拉框选择 utf8

 

然后再重新编译就好啦

 

之后我把启动端口换了一下,clean 后build就ok了

 

 

dig(key, …) → objectclick to toggle source

Extracts the nested value specified by the sequence of idx objects by calling dig at each step, returning nil if any intermediate step is nil.

http://ruby-doc.org/core-2.4.0/Hash.html#method-i-dig

h = { foo: {bar: {baz: 1}}}

h.dig(:foo, :bar, :baz)           #=> 1
h.dig(:foo, :zot, :xyz)           #=> nil

g = { foo: [10, 11, 12] }
g.dig(:foo, 1)                    #=> 11
g.dig(:foo, 1, 0)                 #=> TypeError: Integer does not have #dig method
g.dig(:foo, :bar)                 #=> TypeError: no implicit conversion of Symbol into Integer

举例子:

            if item["ui_type"]["pos"].present?
              display_item.x_axis = item["ui_type"]["pos"]["x"] if item["ui_type"]["pos"]["x"].present?
              display_item.y_axis = item["ui_type"]["pos"]["y"] if item["ui_type"]["pos"]["y"].present?
              display_item.width = item["ui_type"]["pos"]["w"]  if item["ui_type"]["pos"]["w"].present?
              display_item.height = item["ui_type"]["pos"]["h"] if item["ui_type"]["pos"]["h"].present?
            end

改为

         display_item.x_axis = item["ui_type"]["pos"]["x"] if item.dig("ui_type", "pos", "x").present?
         display_item.y_axis = item["ui_type"]["pos"]["y"] if item.dig("ui_type", "pos", "y").present?
         display_item.width = item["ui_type"]["pos"]["w"]  if item.dig("ui_type", "pos", "w").present?
         display_item.height = item["ui_type"]["pos"]["h"] if item.dig("ui_type", "pos", "h").present?

 

 

 

$ git checkout -b cibn-cache-clean
Switched to a new branch ‘cibn-cache-clean’
$ git cherry-pick 9b78e3f6e70cf8ad9bd85b90e36819ea6a77ed32
[cibn-cache-clean bd0c3d2] Add subject cache clear link

 

 

修改git最后一次提交的命令

$ git commit --amend

修改git最后一次提交用户名的相关命令

git config user.name 'wangz'  
git config user.email 'wangz@alib.com'  
git commit  --amend --author=wangz

修改最后一次提交内容的相关文档

$ git commit --amend --help  
usage: git commit [options] [--] <pathspec>...

    -q, --quiet           suppress summary after successful commit
    -v, --verbose         show diff in commit message template

Commit message options
    -F, --file <file>     read message from file
    --author <author>     override author for commit
    --date <date>         override date for commit
    -m, --message <message>
                          commit message
    -c, --reedit-message <commit>
                          reuse and edit message from specified commit
    -C, --reuse-message <commit>
                          reuse message from specified commit
    --fixup <commit>      use autosquash formatted message to fixup specified commit
    --squash <commit>     use autosquash formatted message to squash specified commit
    --reset-author        the commit is authored by me now (used with -C/-c/--amend)
    -s, --signoff         add Signed-off-by:
    -t, --template <file>
                          use specified template file
    -e, --edit            force edit of commit
    --cleanup <default>   how to strip spaces and #comments from message
    --status              include status in commit message template
    -S, --gpg-sign[=<key id>]
                          GPG sign commit

Commit contents options
    -a, --all             commit all changed files
    -i, --include         add specified files to index for commit
    --interactive         interactively add files
    -p, --patch           interactively add changes
    -o, --only            commit only specified files
    -n, --no-verify       bypass pre-commit hook
    --dry-run             show what would be committed
    --short               show status concisely
    --branch              show branch information
    --porcelain           machine-readable output
    --long                show status in long format (default)
    -z, --null            terminate entries with NUL
    --amend               amend previous commit
    --no-post-rewrite     bypass post-rewrite hook
    -u, --untracked-files[=<mode>]
                          show untracked files, optional modes: all, normal, no. (Default: all)

 

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /Users/angela/.rbenv/versions/1.9.3-p545/bin/ruby -r ./siteconf20170106-59264-robjdg.rb extconf.rb --use-system-libraries
checking if the C compiler accepts ... yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future... no
Building nokogiri using system libraries.
libxml2 version 2.6.21 or later is required!
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/angela/.rbenv/versions/1.9.3-p545/bin/ruby
    --help
    --clean
    --use-system-libraries
    --with-zlib-dir
    --without-zlib-dir
    --with-zlib-include
    --without-zlib-include=${zlib-dir}/include
    --with-zlib-lib
    --without-zlib-lib=${zlib-dir}/lib
    --with-xml2-dir
    --without-xml2-dir
    --with-xml2-include
    --without-xml2-include=${xml2-dir}/include
    --with-xml2-lib
    --without-xml2-lib=${xml2-dir}/lib
    --with-libxml-2.0-config
    --without-libxml-2.0-config
    --with-pkg-config
    --without-pkg-config
    --with-xslt-dir
    --without-xslt-dir
    --with-xslt-include
    --without-xslt-include=${xslt-dir}/include
    --with-xslt-lib
    --without-xslt-lib=${xslt-dir}/lib
    --with-libxslt-config
    --without-libxslt-config
    --with-exslt-dir
    --without-exslt-dir
    --with-exslt-include
    --without-exslt-include=${exslt-dir}/include
    --with-exslt-lib
    --without-exslt-lib=${exslt-dir}/lib
    --with-libexslt-config
    --without-libexslt-config

extconf failed, exit code 1

Gem files will remain installed in /Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/extensions/x86_64-darwin-13/1.9.1-static/nokogiri-1.6.7.2/gem_make.out
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:89:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:36:in `block in build'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/tempfile.rb:320:in `open'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/ext_conf_builder.rb:19:in `build'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:161:in `block (2 levels) in build_extension'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:160:in `chdir'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:160:in `block in build_extension'
<internal:prelude>:10:in `synchronize'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:159:in `build_extension'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:198:in `block in build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:195:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/ext/builder.rb:195:in `build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:702:in `build_extensions'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:250:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:90:in `block in install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/rubygems_integration.rb:130:in `preserve_paths'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/source/rubygems.rb:89:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:105:in `block in install_gem_from_spec'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/rubygems_integration.rb:162:in `with_build_args'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:104:in `install_gem_from_spec'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:262:in `block in install_sequentially'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/forwardable.rb:201:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/forwardable.rb:201:in `each'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:261:in `install_sequentially'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:91:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/installer.rb:15:in `install'
/Users/angela/.rbenv/rbenv.d/exec/gem-rehash/rubygems_plugin.rb:27:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli/install.rb:78:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli.rb:145:in `install'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/command.rb:27:in `run'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/invocation.rb:121:in `invoke_command'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor.rb:363:in `dispatch'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/vendor/thor/base.rb:440:in `start'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/cli.rb:9:in `start'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/bin/bundle:20:in `block in <top (required)>'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/lib/bundler/friendly_errors.rb:5:in `with_friendly_errors'
/Users/angela/.rbenv/versions/1.9.3-p545/lib/ruby/gems/1.9.1/gems/bundler-1.6.5/bin/bundle:18:in `<top (required)>'
/Users/angela/.rbenv/versions/1.9.3-p545/bin/bundle:23:in `load'
/Users/angela/.rbenv/versions/1.9.3-p545/bin/bundle:23:in `<main>'
An error occurred while installing nokogiri (1.6.7.2), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.7.2'` succeeds before bundling.

解决方法

brew install --force libxml2 libxslt
brew install --force libiconv

xcode-select --install

 

 

http://api.rubyonrails.org/classes/ActionView/Template.html#method-i-local_assigns

 

Returns a hash with the defined local variables.

Given this sub template rendering:

<%= render "shared/header", { headline: "Welcome", person: person } %>
You can use local_assigns in the sub templates to access the local variables:

local_assigns[:headline] # => "Welcome"

 

 

 

current_index = local_assigns[:index] || default_index
from = (local_assigns[:from] || default_from) + ["#{current_index}:#{component.name}"]
version = :v4

 

json.array! component.get_parts_in_order(@status).each_with_index.to_a do |part, index|
          json.partial! 'api/v2/components/component', component: part, from: from, index: index
        end

 

 

 

http://api.rubyonrails.org/classes/Array.html#method-i-second

 

[27] pry(main)> list = ["a", "b", "c", "d"]
=> ["a", "b", "c", "d"]
[28] pry(main)> list.first
=> "a"
[29] pry(main)> list.second
=> "b"
[30] pry(main)> list.third
=> "c"
[32] pry(main)> list.second_to_last
=> "c"q

 

 

 

The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements. These helper methods extend Action View making them callable within your template files.

只允许 sanitize 方法中指定的标签和属性输出到页面,防止注入

 

sanitize(html, options = {})

 

Sanitizes HTML input, stripping all tags and attributes that aren’t whitelisted.

It also strips href/src attributes with unsafe protocols like javascript:, while also protecting against attempts to use Unicode, ASCII, and hex character references to work around these protocol filters.

The default sanitizer is Rails::Html::WhiteListSanitizer. See Rails HTML Sanitizers for more information.

Custom sanitization rules can also be provided.

Please note that sanitizing user-provided text does not guarantee that the resulting markup is valid or even well-formed. For example, the output may still contain unescaped characters like <>, or &.

  • :tags – An array of allowed tags.
  • :attributes – An array of allowed attributes.
  • :scrubber – A Rails::Html scrubber or Loofah::Scrubber object that defines custom sanitization rules. A custom scrubber takes precedence over custom tags and attributes.

 

module AnnouncementsHelper
  def safe_content(content)
    sanitize(content, tags: %w(b br))
  end
end

 

 

<p>
  <strong><%= t 'content' %></strong>
  <%= safe_content @announcement.content %>
</p>

 

 

http://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html

 

  def search
    @videos = Video.where("videoid LIKE ? or title LIKE ?", "%#{params[:q]}%", "%#{params[:q]}%")

    render :index
  end 
使用 hash 的写法
  def search
    @videos = Video.where("videoid LIKE :q or title LIKE :q", q: "%#{params[:q]}%")

    render :index
  end