如何为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 

posted @ 2019-04-10 10:39  Mr-chen  阅读(205)  评论(0编辑  收藏  举报