zoukankan      html  css  js  c++  java
  • 如何为Rails作贡献:例增加rich_text field generators

    如何为Rails作贡献

    例增加rich_text field generators

    下载https://github.com/rails/rails

    打开atom,在

    rails generate model Post name:rich_text
    #产生attachment, 就是在model上增加:has_rich_text

    新建rails new rich_text,

    打开文件Gemfile,更改rails包的path:

    #例如:
    gem 'rails', path: "../rails"

    然后bundle install就会更新gem。

    在新的程序上使用手脚架:

    rails g scaffold Post body:text_area

    会自动在_form.html.erb上添加:

    <div class="field">
      <%= form.label :body %>
      <%= form.rich_text_area :body%>
    </div>

    但是没有在model上添加has_rich_area :body,可以通过在源代码的

    activerecord/lib/rails/generators/active_record/model/template/model.rb.tt上增加下面的代码:

    <% attributes.select(&:rich_text?).each do |attribute| %>
      has_rich_text :<%= attribute.name %>
    <% end %>

    在同目录generated_attribute.rb加上

    def rich_text?
      tyep == :rich_text
    end

    然后在terminal上:

    //删除之前建立的手脚架
    rails destroy scaffold Post
    //重新建立
    rails g scaffold scaffold Post body:rich_text

    测试完成后,即可到git push request 

  • 相关阅读:
    007_2 (变式)青蛙跳台阶
    008 二进制中1的个数
    009 数值的整数次方
    007_1 斐波那契数列的非递归解法
    Linux TTY函数跟踪
    Linux UART介绍
    Linux TTY介绍
    Linux音频编程
    Jasper语音助理
    Raspberry Pi使用
  • 原文地址:https://www.cnblogs.com/chentianwei/p/10681888.html
Copyright © 2011-2022 走看看