0

I am using Railscasts 182 to crop the uploaded image. As per the video I implemented this:

I am uploading an image in profile page. Here is my profile controller:

def edit
  @profile = current_user.profile
  if @profile.photo.nil?
    redirect_to current_user.profile
  else
    render :action => "crop"
  end
end

def update
  @profile = current_user.profile
  if @profile.update_attributes(params[:profile])
    if @profile.photo.nil?
      redirect_to current_user.profile
    else
      render :action => "crop"
    end
  else
    render :edit
  end
end

As per the video my crop.html.erb file is:

<% "Crop avatar" %>

<% content_for(:head) do %>
  <%= stylesheet_link_tag "jquery.Jcrop" %>
  <%= javascript_include_tag "jquery.Jcrop.min" %>
  <script type="text/javascript">
  $(function(){
    $("#cropbox").jCrop();
  });
  </script>
<% end %>

<%= image_tag @profile.photo.avatar.url(:big), :id => "cropbox" %>

And I added these in my application.html.erb:

<%= javascript_include_tag "jquery.min" %>
<%= yield(:head) %>

When I submit an image, it displays the plain image. It does not show the selection cursor and hence can't select an area on the image as it is shown in the video.

I guess Jcrop is not working. Can anybody tell what would be the issue?

jvperrin
  • 3,368
  • 1
  • 23
  • 33
user1977201
  • 61
  • 1
  • 9

1 Answers1

0

Make sure that jquery.Jcrop.min is being included in the resulted HTML file by viewing the source or running $("#cropbox").jCrop(); in the firebug.

If it is not then try to add this line //= require jquery.Jcrop.min to your application.js then precompile your assets.

If it is still not being included, then a desperate solution would be removing content_for head(:head) line which for some reason fails to append your js code to the header (that's what I ended up doing).

Hammam
  • 76
  • 3