• 如何保存ActionMailbox inbound HTML email和关于ActionText与ActiveStorage的附加


    gi代码:

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


    新建一个rails6

    需要

    gem 'image_processing'

    gem 'whenever', require: false

    rails action_text:install

    (参考https://www.cnblogs.com/chentianwei/p/10515183.html ,

    https://www.cnblogs.com/chentianwei/p/10655122.html )

    rails webpacker:install:stimulus

    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 %>

    配置:

  • 相关阅读:
    第十四周总结
    《走出软件作坊》读后感
    航空公司信息可视化
    周总结
    REDIS实验
    第二阶段个人总结07
    第二阶段个人总结06
    第二阶段个人总结05
    第二阶段个人总结04
    第二阶段个人总结03
  • 原文地址:https://www.cnblogs.com/chentianwei/p/10972108.html
Copyright © 2020-2023  润新知