我从无价的资源堆栈流中学到了很多东西。我非常感谢所做出的许多出色贡献。万岁开源和那些真正的开源!
对于此处已有的所有重要信息,我无法在此处找到解决问题的正确方法。让我解释一下。
使用RefineryCMS v.2.0.9我在rails应用程序中生成了一个引擎,用于呈现“Portfolios”。 '投资组合'has_many':展览'。 ':展览'belongs_to':投资组合',如下所示。
模型属性:img_orginal - 包含用于Dragonfly图像上传的uid。这应该工作,图像上传uid被提交到数据库,并可以按预期调用到views / portfolio / show.html.erb视图。该网站旨在响应。如果它要响应,它需要一套由原始生成的调整大小的拇指。这些需要在以下情况下由Dragonfly生成:img_original上传并通过后端表单提交。到目前为止,我无法使用展品模型中的Dragonfly image_accessor来实现这一目标。我在创建尝试时收到了followin异常。
无法批量分配受保护的属性:img_original ActiveModel :: MassAssignmentSecurity :: Refinery中的错误:: Portfolios :: Admin :: ExhibitsController #crera
两个数据库都存在,并通过'展览'模型中的':portfolio_id'外键正确链接。根据当前的rails最佳实践,所有模型属性都列入白名单。
我错过了什么?控制器方法不对我假设,我无法弄清楚它们应该如何。是否有必要修改引擎控制器来调用Page Image类或Dragonfly本身?我是否需要更改routes.rb。有人可以建议我如何定义Controller的创建和更新方法。它是否必要,因为它们应该已经由主炼油厂app的page_images控制器定义。
我已尝试使用image_accessor在Dragonfly文档中建议的方法无济于事。以下是迄今采取的一些方法。
即。
image_accessor :img_original do
after_assign :crop_thumb #method defined below
#:resize_mobile,
#:resize_tablet,
#:resize_desktop
# OR
# copy_to(:img_thumb) do
# |a| a.thumb('100x100')
# end
# OR different block syntax
# copy_to(:img_thumb) do {|a| a.thumb('100x100')}
end
def crop_thumb
@exhibit.img_thumb = @exhibit.img_original.process(:resize_and_crop,
:width => 100,
:height=> 100,
:x => :x_focus,
:y => :y_focus).encode(:jpg, '-quality 60').apply
end
#def resize_mobile,
@exhibit.img_mobile = @exhibit.img_original.process(etc.
#end
#def resize_tablet,
etc.
我对此非常陌生,到目前为止,我一直坚持不懈地研究实现它。然而我来到这里却无法破解它。我将不胜感激。谢谢。
下面的代码示例和环境信息。
环境; Ubuntu 12.10 RubyMine IDE Ruby 1.9.3 RVM处理宝石 Rails 3.2.9 SQLite开发数据库 RefineryCMS(包括page_images和查询插件) 蜻蜓0.9.14
通过这些迁移生成的Portfolio Engine
# This migration comes from refinery_portfolios (originally 1)
class CreatePortfoliosPortfolios < ActiveRecord::Migration
def up
create_table :refinery_portfolios do |t|
t.string :title
t.integer :year
t.text :description
t.integer :publication_id
t.integer :commentary_id
t.integer :position
t.timestamps
end
end
def down
if defined?(::Refinery::UserPlugin)
::Refinery::UserPlugin.destroy_all({:name => "refinerycms-portfolios"})
end
if defined?(::Refinery::Page)
::Refinery::Page.delete_all({:link_url => "/portfolios/portfolios"})
end
drop_table :refinery_portfolios
end
end
和
# This migration comes from refinery_portfolios (originally 2)
class CreatePortfoliosExhibits < ActiveRecord::Migration
def up
create_table :refinery_portfolios_exhibits do |t|
t.string :title
t.integer :cat_num
t.integer :year
t.string :medium
t.integer :width
t.integer :height
t.integer :img_original_id
t.string :img_thumb
t.string :img_mobile
t.string :img_tablet
t.string :img_desktop
t.integer :x_focus
t.integer :y_focus
t.text :history
t.integer :portfolio_id
t.boolean :sold
t.integer :position
t.timestamps
end
end
def down
if defined?(::Refinery::UserPlugin)
::Refinery::UserPlugin.destroy_all({:name => "refinerycms-portfolios"})
end
if defined?(::Refinery::Page)
::Refinery::Page.delete_all({:link_url => "/portfolios/exhibits"})
end
drop_table :refinery_portfolios_exhibits
end
end
并且refinery_portfolios_exhibits表列标题已更改
Exhibits table column header changed via migration
class FixColumnName < ActiveRecord::Migration
def change
rename_column :refinery_portfolios_exhibits, :img_original_id, :img_original_uid
rename_column :refinery_portfolios_exhibits, :img_thumb, :img_thumb_uid
rename_column :refinery_portfolios_exhibits, :img_mobile, :img_mobile_uid
rename_column :refinery_portfolios_exhibits, :img_tablet, :img_tablet_uid
rename_column :refinery_portfolios_exhibits, :img_desktop, :img_desktop_uid
end
end
投资组合模型包含投资组合元数据,称为“portfolio.rb” has_many展览 模块炼油厂 模块组合 class Portfolio&lt;炼油厂::核心:: BaseModel self.table_name ='refinery_portfolios'
attr_accessible :title,
:year,
:description,
:publication_id,
:commentary_id,
:position
acts_as_indexed :fields => [:title]
validates :title, :presence => true, :uniqueness => true
belongs_to :publication, :class_name => '::Refinery::Resource'
belongs_to :commentary, :class_name => '::Refinery::Resource'
# destroy all exhibits when a portfolio is destroyed
has_many :exhibits, :dependent => :destroy
end
end
end
展览模型包含图像链接和相关元数据,称为“exhibit.rb”; belongs_to portfolio
require 'dragonfly/rails/images'
module Refinery
module Portfolios
class Exhibit < Refinery::Core::BaseModel
attr_accessible :title,
:cat_num,
:year,
:medium,
:width,
:height,
:img_original_uid, #image upload uid from refinery_images table
:img_thumb_uid, #commit resize uid here
:img_mobile_uid, #here
:img_tablet_uid, #here
:img_desktop_uid, #and here
:x_focus,
:y_focus,
:history,
:portfolio_id, #foreign key, associates exhbit with portfolio
:sold,
:position
acts_as_indexed :fields => [:title, :medium, :year, :cat_num]
validates :title, :presence => true, :uniqueness => true
validates :year, :length => { :is => 4,
:message => "Four digit year format,(yyyy) eg. 2013"}
validates :img_original_uid, :presence => true, :uniqueness => true
validates :portfolio_id, :presence => true
validates_associated :portfolio
validates :x_focus, :presence => true
validates :y_focus, :presence => true
validates :sold, :inclusion => {:in => [true, false]}
belongs_to :img_original, :class_name => '::Refinery::Image'
belongs_to :portfolio, :class_name => 'Portfolio', :foreign_key => 'portfolio_id'
end
end
end
Controller'admin / exhibit.rb'
module Refinery
module Portfolios
module Admin
class ExhibitsController < ::Refinery::AdminController
before_filter :find_all_portfolios
crudify :'refinery/portfolios/exhibit', :xhr_paging => true
protected
def find_all_portfolios
@portfolios = Refinery::Portfolios::Portfolio.all
end
end
end
end
end
控制器'exhibit.rb'
module Refinery
module Portfolios
class ExhibitsController < ::ApplicationController
before_filter :find_all_exhibits
before_filter :find_page
def index
#@exhibits = Exhibit.all(:include => :portfolio)
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @exhibit in the line below:
present(@exhibit)
end
def show
@exhibit = Exhibit.find(params[:id])
# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @exhibit in the line below:
present(@exhibit)
end
protected
def find_all_exhibits
@exhibits = Exhibit.order('position ASC')
end
def find_page
@page = ::Refinery::Page.where(:link_url => "/exhibits").first
end
end
end
end
答案 0 :(得分:0)
我猜你自从10个月前问过以后就不再关心这个了,但是在你的展览模型中你试过改变
attr_accessible :img_original_uid
到
attr_accessible :img_original
错误来自img_original字段,但您可以访问img_original_uid。我也是蜻蜓的新手......