5

I'm using redactor_rails gem with carrierwave. There's two places where I need text editor with picture upload, and I want to make different picture size for every editor.

If I use version then I have two sizes for every picture and I dont know how to change picture version in text field.

The main idea is to run it's own resize process for every editor uploader in redactor_rail_picture_uploader

How do I do that?

konclave
  • 648
  • 1
  • 7
  • 19
  • Seems that it's not possible to do it. I had to override some gem methods to make it work. – konclave Feb 08 '13 at 15:02
  • Can you please answer your question with the solution and the code? I'd like to do this too and you can than accept your answer.. – Tim Baas Mar 23 '13 at 17:42

1 Answers1

2

May be it's not the perfect way, but it works.

I've made several versions of uploaded files in: redactor_rails_picture_uploader.rb

version :item_text do
  process :resize_to_limit => [478, 478]
end

version :thumb do
  process :resize_to_fill => [100, 100]
end

Created initializer and redefined method 'create' of class RedactorRails::PicturesController there. Now it saves the version that I pass with the form by 'version' param.

RedactorRails::PicturesController.class_eval do
  def create
    @picture = RedactorRails::Picture.new

    file = params[:file]
    version = params[:version]

    @picture.data = RedactorRails::Http.normalize_param(file, request)
    if @picture.respond_to?(:user_id)
      @picture.user = current_user
      @picture.assetable = current_user
    end

    if @picture.save
      if version 
        file_link = @picture.send(:url, version)
      else 
        file_link = @picture.url
      end 

      render :text => { :filelink => file_link }.to_json 

    else
      render :nothing => true
    end
  end
end

Finally added hidden input with the value of the version from uploader I want to save in this form:

%input{:id => 'redactor_version', :value => 'item_text', :type => 'hidden'}

Something like this.

stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189
konclave
  • 648
  • 1
  • 7
  • 19
  • hi @barba , could you please explain how did you implement Redactor for rich text box in ruby on rails application. I tried but could not get expected output. any suggestion would be appreciating. – Vieenay Siingh Apr 30 '13 at 11:31
  • 1
    Just loaded a redactor js module and set a 'redactor' class for the textarea. – konclave May 10 '13 at 17:38