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 

  • 相关阅读:
    多层神经网络与C++实现
    反向传导算法的推导
    sizeof()和strlen()的区别与联系
    Pascal’s Triangle
    Multiply Strings
    spring boot 数据源 配置
    spring boot 静态资源。。
    spring boot 配置 beetl 视图解析器
    spring 使用junit
    spring aspectj 注解
  • 原文地址:https://www.cnblogs.com/chentianwei/p/10681888.html
Copyright © 2011-2022 走看看