SammyLin / redactor-rails

This repo is deprecated. Please check out official gem for Redactor 2. https://github.com/Redactor2/redactor2_rails
MIT License
389 stars 254 forks source link

Use redactor-rails without devise #85

Closed benoitr closed 10 years ago

benoitr commented 10 years ago

In the documentation, it seems that we could use redactor-rails without the devise option.

However, it seems that user_id is needed. Otherwise, it raises an error due to redactor_authenticate_user! (before_filter)

I've succeeded to implement this like so:

config/redactor.rb

# Overrides the user class

module RedactorRails
  def self.devise_user
  end
end

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
 ...

  def redactor_authenticate_user!
  end

  def redactor_current_user
  end
end

Is there is a better way to implement this or is there a bug when not passing the devise option ? Thanks

hovsater commented 10 years ago

I solved this by not relying on including the ActiveRecord ORM.

Instead of having this

class RedactorRails::Asset < ActiveRecord::Base
  include RedactorRails::Orm::ActiveRecord::AssetBase
  delegate :url, :current_path, :size, :content_type, :filename, :to => :data
  validates_presence_of :data
end

I have this

require 'redactor-rails/orm/base'

class RedactorRails::Asset < ActiveRecord::Base
  include RedactorRails::Orm::Base::AssetBase::InstanceMethods

  self.table_name = 'redactor_assets'

  belongs_to :assetable, :polymorphic => true

  attr_accessible :data, :assetable_type, :assetable_id, :assetable

  delegate :url, :current_path, :size, :content_type, :filename, :to => :data
  validates_presence_of :data
end
Arcolye commented 10 years ago

The above doesn't work. The only way I got it to work without authentication was to go back to an older version

gem 'redactor-rails', '0.3.3'

Then just make sure you take the user_id column out of the migration (or make a new migration remove the user_id column if it's already in the DB), and you're good to go.

Arcolye commented 10 years ago

KevinSjoberg's workaround works in Rails 4 if you delete the attr_accessible line.