Forum: Ruby on Rails Form not invoking "create" action in production

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C0b6fb3807d7d4f255463ed168c75897?d=identicon&s=25 Trevor Turk (Guest)
on 2007-04-03 06:18
(Received via mailing list)
I've officially lost my mind. I've got a form that looks like this:

<%= error_messages_for :avatar %>
<% form_for(:avatar, :url => avatars_path, :html => { :multipart =>
true }) do |f| %>
  <p><%= f.file_field :uploaded_data %></p>
  <p><%= submit_tag "Upload" %>
<% end %>

It uses attachment_fu to allow users to upload avatars. Everything
works fine when I'm in development, but in production the "create"
action is not invoked from some reason.

I'm using standard RESTful routes, like this:

map.resources :avatars

And I've got a "create" action in my avatars controller:

def create
  @avatar = params[:avatar]
  respond_to do |format|
      flash[:notice] = 'Avatar was successfully created.'
      format.html { redirect_to avatars_path }
      format.xml  { head :created, :location => avatars_path }
      format.html { render :action => "new" }
      format.xml  { render :xml => @avatar.errors.to_xml }

In development, everything works as expected. My production.log file
shows me this following when I try to upload a new avatar:

Processing AvatarsController#new (for at 2007-04-02
21:11:35) [GET]
  Parameters: {"action"=>"new", "controller"=>"avatars"}
Rendering  within layouts/application
Rendering avatars/new
Completed in 0.15629 (6 reqs/sec) | Rendering: 0.01185 (7%) | DB:
0.14027 (89%) | 200 OK

Processing AvatarsController#index (for at 2007-04-02
21:11:45) [GET]
  Parameters: {"action"=>"index", "controller"=>"avatars"}
Rendering content_typetext/htmlactionindexlayoutfalse within layouts/
Rendering avatars/index
Completed in 0.13149 (7 reqs/sec) | Rendering: 0.06164 (46%) | DB:
0.06527 (49%) | 200 OK

In development, things looks right, though:

Processing AvatarsController#new (for at 2007-04-03
16:14:50) [GET]
  Parameters: {"action"=>"new", "controller"=>"avatars"}
Rendering  within layouts/application
Rendering avatars/new
Completed in 0.93098 (1 reqs/sec) | Rendering: 0.23151 (24%) | DB:
0.15408 (16%) | 200 OK

Processing AvatarsController#create (for at 2007-04-03
16:14:57) [POST]
  Parameters: {"commit"=>"Upload", "action"=>"create",
"controller"=>"avatars", "avatar"=>{"uploaded_data"=>#<File:/tmp/
Redirected to http://localhost:3000/avatars
Completed in 0.54049 (1 reqs/sec) | DB: 0.06105 (11%) | 302 Found

Processing AvatarsController#index (for at 2007-04-03
16:14:59) [GET]
  Parameters: {"action"=>"index", "controller"=>"avatars"}
Rendering content_typetext/htmllayoutfalseactionindex within layouts/
Rendering avatars/index
Completed in 0.96327 (1 reqs/sec) | Rendering: 0.49423 (51%) | DB:
0.05750 (5%) | 200 OK

I just don't get why the "create" action isn't being invoked in
production with this code. Is there something wrong with my form that
I'm missing? I can't seem to figure this one out.

Any help would be greatly appreciated.
C0b6fb3807d7d4f255463ed168c75897?d=identicon&s=25 Trevor Turk (Guest)
on 2007-04-05 02:15
(Received via mailing list)
I've gotten a response from Media Temple on this, although I'm still
not sure how I'll resolve the issue. I'm sure I'm not the first or
last person who'll try to do what I'm doing, so I'm hopeful that I'll
find a solution. Here's what they said:

The problem you are running into is not caused by code or
configuration, but coincidence. Your controller is exposed as "/
and you have a directory in your public folder called files.

When your form is created, the action is "/files". When this post
request hits the Grid, Apache sees that request (
and that there is a directory there, and so appends a slash (http:// and redirects the browser to the new URL. This is
standard Apache behavior since most requests for a directory name are
usually for the directory's contents rather than the directory
Since Apache does the redirect, the post turns into a get before your
Rails application even has a chance to see it. To test this out,
rename your files directory to any other name and you will see that
the post request starts working again.

And, seeing that you are also having issues with the /headers and /
avatars and that there are matching directories in your public
directory, the same issue is probably happening there.


If anyone has an idea of how to work around this behavior (changing
the Apache config?) please let me know. Otherwise, I'll update this
post when I figure out a solution.

- Trevor
F4fff657afcb2768000050a7742e640f?d=identicon&s=25 Sam Storie (Guest)
on 2007-05-04 23:50
(Received via mailing list)
> If anyone has an idea of how to work around this behavior (changing
> the Apache config?) please let me know. Otherwise, I'll update this
> post when I figure out a solution.

Their advice is right on, and makes sense once I read it. I had the
same problem, and the only thing I can think of is that Mike Clark
wasn't using apache when he wrote that tutorial.

Anyway, to work around this you need to use the :path_prefix option in
your has_attachment statement inside your model:

## Begin model ##
class Mugshot < ActiveRecord::Base

  has_attachment :content_type => :image,
                 :storage => :file_system,
                 :max_size => 500.kilobytes,
                 :resize_to => '320x200>',
                 :thumbnails => { :thumb => '100x100>' },
                :path_prefix => "public/something_besides_avatars"


## end model ##

This will prevent apache from hijacking the request because the
directory you created to hold the images won't match the rails action
you're trying to invoke. Once I changed that setting things started
working for me.

Does that help?
C0b6fb3807d7d4f255463ed168c75897?d=identicon&s=25 Trevor Turk (Guest)
on 2007-05-29 20:42
(Received via mailing list)
Actually, I've added the following to my .htaccess:

DirectorySlash Off

... which solves the problem. You can read more about that here:

I was wondering if there's any reason why this shouldn't be a part of
the default Rails .htaccess file...?

- Trevor

On May 4, 4:50 pm, Sam  Storie <> wrote:

> :path_prefix => "public/something_besides_avatars"
This topic is locked and can not be replied to.