简体   繁体   English

Refinerycms如何将图像上传到事件,但图像已保存到finery_images表

[英]Refinerycms how to upload image to events, but the image saved to refinery_images table

newbie in rails, 新手,

i'm trying to use refinerycms in my rails app, refinery already available to upload an images to the database, i'm trying to combine it to an extension that i use, "events" extension, so when i create a new events that should create 2 object, events to refinery_event table which have image_id as a foreign key for images id, and the event image attribute that will be saved to refinery_images, 我正在尝试在我的Rails应用程序中使用fineryrycms,已经可以将图像上传到数据库的炼油厂,我正在尝试将其组合到我使用的扩展名“事件”扩展名中,因此当我创建一个新的事件时应该创建2个对象,将事件image_id作为图像ID的外键,并将其保存到fineryry_images,

i've add a migrations image_id column to refinery_event and put this relation to event.rb models 我已将迁徙image_id列添加到fineryry_event,并将此关系添加到event.rb模型中

belongs_to :image_id, :class_name => '::Refinery::Image'

add this in event_controller.rb 在event_controller.rb中添加

def image_params
  params.require(:event).permit(:image_name, :image_size, :image_width, :image_height, :created_at, :updated_at)
end

def new
  @event = Event.new
  @image_id = Refinery::Image.new
end

def create
  @event = Event.new(event_params)
  @image_id = Refinery::Image.new(image_params)

  if @event.save
      begin
        Mailer.notification(@event, request).deliver_now
      rescue => e
        logger.warn "There was an error delivering the event notification.\n#{e.message}\n"
      end

      if Event.column_names.map(&:to_s).include?('email')
        begin
          Mailer.confirmation(@event, request).deliver_now
        rescue => e
          logger.warn "There was an error delivering the event confirmation:\n#{e.message}\n"
        end
      else
        logger.warn "Please add an 'email' field to Event if you wish to send confirmation emails when forms are submitted."
      end

      redirect_to refinery.thank_you_events_events_path
    else
      render :action => 'new'
  end
end

def event_params
 params.require(:event).permit(:nama, :deskripsi, :periode_start, :periode_end, :lokasi, :jumlah, :gender_id, :age_id, :event_types_id, :des_acara, :key_kata, :tipe_sponsor, :dana, :exposure, :enggagement, :image_id)
end

and this is the form looks like, 这是表格的样子,

<%= form_for [refinery, :events, @event], :html => { :multipart => true } do |f| %>
  <%= render '/refinery/admin/error_messages',
             :object => @event,
             :include_object_name => true  %>

  <div class='field nama_field string_field'>
    <%= f.label :nama %>
    <%= f.text_field :nama %>
  </div>

  <div class='field deskripsi_field text_field'>
    <%= f.label :deskripsi %>
    <%= f.text_area :deskripsi, :rows => 8 %>
  </div>

  <div class="field">
    <p>
      <%= f.file_field :image_id %>
    </p>
  </div>

  <div class='actions'>
    <%= f.submit t('.send') %>
  </div>
<% end %>

and i'm stuck what else ? 而且我还被卡住了吗? how to make this form work? 如何使此表格生效? anyone can teach me? 有人可以教我吗?

thanks.. 谢谢..

As answered here: https://groups.google.com/forum/#!msg/refinery-cms/5RbAD079IPc/nVFGKdnfAQAJ 如此处回答: https : //groups.google.com/forum/#!msg/ refinery-cms/ 5RbAD079IPc/nVFGKdnfAQAJ

You can use the built in image picker, as we can see if we use the generator: 您可以使用内置的图像选择器,因为我们可以看到是否使用了生成器:

$ rails generate refinery:engine event nama:string deskripsi:text image:image

This creates the following admin controller: 这将创建以下管理控制器:

module Refinery
  module Events
    module Admin
      class EventsController < ::Refinery::AdminController


        crudify :'refinery/events/event',
                :title_attribute => 'nama'


        private


        # Only allow a trusted parameter "white list" through.
        def event_params
          params.require(:event).permit(:nama, :deskripsi, :image_id)
        end
      end
    end
  end
end

And the following template: 和以下模板:

<%= form_for [refinery, :events_admin, @event] do |f| -%>
  <%= render '/refinery/admin/error_messages',

              :object => @event,
              :include_object_name => true
%>


  <div class='field'>
    <%= f.label :nama -%>
    <%= f.text_field :nama, :class => 'larger widest' -%>
  </div>


  <div class='field'>
    <%= render '/refinery/admin/wysiwyg',
                :f => f,
                :fields => [:deskripsi],
                :object => "events/event" -%>
  </div>


  <div class='field'>
    <%= f.label :image -%>
    <%= render '/refinery/admin/image_picker',
               :f => f,
               :field => :image_id,
               :image => @event.image,
               :toggle_image_display => false -%>
  </div>


  <%= render '/refinery/admin/form_actions', :f => f,
             :continue_editing => false,
             :delete_title => t('delete', :scope => 'refinery.events.admin.events.event'),
             :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @event.nama) -%>
<% end -%>


<% content_for :javascripts do -%>
  <script>
    $(document).ready(function(){
      page_options.init(false, '', '');
    });
  </script>
<% end -%>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何才能得到finerycms以显示来自Amazon S3与/ system / images…的上传图像URL? - How can I get refinerycms to display uploaded image urls from Amazon S3 versus /system/images…? RefineryCMS图像上传无法在生产环境中使用 - RefineryCMS images upload not working in production 没有路线匹配的精炼厂图像上传(如何更改精炼厂的默认图像路线?) - Refinery Image Uploading giving no route match (How do you change default image route in refinery?) 添加了图像上传进度栏(Paperclip,Javascript),但图像本身未保存。 我怎样才能解决这个问题? - Added a image upload progress bar (Paperclip, Javascript), but images themselves are not being saved. How can I fix this? 如何在lightery-cms网站上添加灯箱式图片库? - How to add a lightbox style image gallery to a refinery-cms website? RefineryCMS图片缩略图未显示 - RefineryCMS image thumbnails not showing up Refinerycms没有生成图像场 - Refinerycms did not generate image field refinerycms图像无法加载 - 蜻蜓错误 - refinerycms image not loading - dragonfly error 如何在Rails中将图像上传并保存到/ assets / images - How to upload and save an image to /assets/images in Rails RefineryCMS-在上载时使用Dragonfly进行多次调整的自定义图像引擎-尝试将uid提交到数据库时出现MassAssign错误 - RefineryCMS - Custom Image Engine using Dragonfly for Multiple Resize on upload - MassAssign Error when trying commit uid to database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM