如何保存ActionMailbox inbound HTML email和關於ActionText與ActiveStorage的附加

gi代碼:javascript

https://github.com/gorails-screencasts/action-mailbox-action-text/commit/3aeedc09441696c9489ed6c16c5245a01cad0903html

 


 

新建一個rails6java

須要webpack

gem 'image_processing'git

gem 'whenever', require: falsegithub

 

rails action_text:installweb

(參考http://www.javashuo.com/article/p-mdfkqems-mm.html ,app

http://www.javashuo.com/article/p-ktiyityk-du.html )post

 

rails webpacker:install:stimulusui

yarn add tributejs

#app/javascript/packs/application.js
#...
+require("trix")
+require("@rails/actiontext")

 

 

rails g scaffold Post title:string

rails db:migrate後

#app/models/post.rb
# 這裏給post記錄掛上關聯的actiontext和attachment。
class Post < ApplicationRecord
  has_rich_text :body
  has_many_attached :attachments
end

 

 

rails action_mailbox:install

全部入境的郵件都讓posts處理。

#app/mailboxes/application_mailbox.rb
class ApplicationMailbox < ActionMailbox::Base
  # routing /something/i => :somewhere
  routing :all => :posts
end

 

 

rails g mailbox Posts

..

 

 

app/views/posts/_form.html.erb 修改代碼,添加richtext,並根據post是否存在,添加刪除和返回按鈕。

  <div class="field">
    <%= form.label :title %>
    <%= form.text_field :title, class: 'form-control' %>
  </div>

  <div class="form-group">
    <%= form.label :body %>
    <%= form.rich_text_area :body, class: 'form-control' %>
  </div>

  <div class="form-group">
    <% if post.persisted? %>
      <div class="float-right">
        <%= link_to "Destroy", post, method: :delete, class:'text-danger', data: {confirm: "Are you sure?"}%>
      </div>
    <% end %>

    <%= form.submit class: 'btn btn-primary'%>

    <% if post.persisted? %>
      <%= link_to "Cancel", post, class: "btn btn-link"%>
    <% else %>
            <%= link_to "Cancel", posts_path, class: "btn btn-link"%>
    <% end %>
  </div>
<% end %>

 

 

app/views/posts/index.html.erb 修改代碼:

+  <td><%= post.body %></td>

 

app/views/posts/show.html.erb 修改代碼:

<div class="page-header">
  <%= link_to posts_path, class: 'btn btn-default' do %>
    All Posts
  <% end %>
  <%= link_to edit_post_path(@post), class: 'btn btn-primary' do %>
    Edit
  <% end %>
  <h1>Show post</h1>
</div>

<dl class="dl-horizontal">
  <dt>Title:</dt>
  <dd><%= @post.title %></dd>

  <dt>Body:</dt>
  <dd><%= @post.body %></dd>

</dl>

<% @post.attachments.each do |attachment| %>
  <div><%= link_to attachment.filename, attachment %></div>
<% end %>

 

 

配置:

相關文章
相關標籤/搜索