Forum: Ruby on Rails Rmagick wouldn't load on server for windows

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Richard Y. (Guest)
on 2008-10-28 21:23
In windows, i'm trying to load rmagick for my app so i put

  require 'RMagick'

in environment.rb but the server wouldn't start and it gives me this
error:


C:/ruby/lib/ruby/gems/1.8/gems/rmagick-2.6.0-x86-mswin32/ext/RMagick2.so
(LoadError)
  from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in
`require'
  from
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in
`require'
  from
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:355:in
`new_constants_in'
  from
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in
`require'
  from
C:/ruby/lib/ruby/gems/1.8/gems/rmagick-2.6.0-x86-mswin32/lib/RMagick.rb:11
  from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in
`gem_original_require'
  from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:32:in
`require'
  from
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.1.1/lib/active_support/dependencies.rb:510:in
`require'
   ... 18 levels...
  from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
  from ./script/server:3
  from -e:4:in `load'
  from -e:4


the file is there but it won't load...any advice? ^_^!
Rick (Guest)
on 2008-10-29 04:11
(Received via mailing list)
Was RMagick2.so built under windows?

On Oct 28, 9:23 am, Richard Y. <removed_email_address@domain.invalid>
Richard Y. (Guest)
on 2008-10-29 04:18
yes i'm running on windows at the moment.

well i got the rmagick to load and put the

required "Rmagick" in the environment.rb

but when i try to post something with image it rolls back and does not
post.  i followed the guide from the advanced rails recipes and just
changed the names around but bleh.

the view:

<% form_for(@item, :html => { :multipart => true }) do |f| %>
  <%= error_messages_for :item, :image %>

  <p>
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </p>
  <p>
    <%= f.label :description %><br />
    <%= f.text_area :description %>
  </p>
  <p>
    <%= label :item, :image %>
    <%= file_field_tag :image_file %>
    <span class="hint">
    We accept JPEG, GIF, or PNG files up to 500 KB.
</span>
</p>
  <p>
<%= f.label :price %><br />
<%= f.text_field :price %>
</p>
  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>

controller

def new
    @item = Item.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @item }
    end
  end

  # GET /items/1/edit
  def edit
    @item = Item.find(params[:id])
  end

  # POST /items
  # POST /items.xml
  def create
    @item = Item.new(params[:item])
    @image = Image.new(:uploaded_data => params[:image_file])

    @service = ItemService.new(@item, @image)

    respond_to do |format|
      if @service.save
        flash[:notice] = 'Item was successfully created.'
        format.html { redirect_to(@item) }
        format.xml  { render :xml => @item,
                             :status => :created,
                             :location => @item }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @item.errors,
                             :status => :unprocessable_entity }
      end
    end

items_helper.rb

module ItemsHelper

  def image_for(item, size = :medium)
    if item.image
      image_image = item.image.public_filename(size)
      link_to image_tag(image_image), item.image.public_filename
    else
      image_tag("blank-image-#{size}.png" )
    end
  end

end


item_service.rb

class ItemService

  attr_reader :item, :image

  def initialize(item, image)
    @item = item
    @image = image
  end

  def save
    return false unless valid?
    begin
      Image.transaction do
        if @image.new_record?
          @item.image.destroy if @item.cover
          @image.item = @item
          @image.save!
        end
        @item.save!
        true
        end
    rescue
      false
    end
  end

  def valid?
    @item.valid? && @image.valid?
  end

  def update_attributes(item_attributes, image_file)
    @item.attributes = item_attributes
    unless image_file.blank?
      @image = Image.new(:uploaded_data => image_file)
    end
    save
  end

end


development.log

Processing ItemsController#create (for 127.0.0.1 at 2008-10-28 22:08:46)
[POST]
  Session ID:
BAh7BzoMY3NyZl9pZCIlMDc3Y2M3ZGVjN2U5OWFhMGY5ZDUzMTQ1ZTRlYTc1
ZGEiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh
c2h7AAY6CkB1c2VkewA=--4332f39dc3fdbc9fc0d4d317ca2c57f1481d87df
  Parameters:
{"image_file"=>#<File:C:/Users/HYUKYO~1/AppData/Local/Temp/CGI6348-3>,
"commit"=>"Create",
"authenticity_token"=>"e798b2552991572d78d139f4268655e69369ee32",
"action"=>"create", "controller"=>"items", "item"=>{"title"=>"adf",
"price"=>"23", "description"=>"asdfasdf"}}
  Item Columns (0.004000)   SHOW FIELDS FROM
`items`
  Image Columns (0.004000)   SHOW FIELDS FROM
`images`
  SQL (0.001000)   BEGIN
  SQL (0.000000)   ROLLBACK
Rendering template within layouts/items
Rendering items/new
Completed in 0.23000 (4 reqs/sec) | Rendering: 0.00400 (1%) | DB:
0.00900 (3%) | 200 OK [http://localhost/items]
This topic is locked and can not be replied to.