2

I think the issue could be strong parameters in Rails 4, but I am not sure.

Here is what I have.

All I am trying to do is create a post, but when it gets submitted I get this error:

Started POST "/posts" for 127.0.0.1 at 2014-08-28 06:06:57 -0500
Processing by PostsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"daURJjzq2EMfiQZ/uiD/0ADg=", "post"=>{"status"=>"confirmed", "title"=>"Ashlee lost 10 pounds in 5 weeks", "photo"=>#<ActionDispatch::Http::UploadedFile:0x0000010652d3c8 @tempfile=#<Tempfile:/var/folders/0f/hgplttnd7dg6q9m62qtbnpn00000gn/T/RackMultipart20140828-87750-gyz4np>, @original_filename="Ashlee-Testimonial.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"post[photo]\"; filename=\"Ashlee-Testimonial.png\"\r\nContent-Type: image/png\r\n">, "body"=>"Ashlee lost 10 pounds in 5 weeks."}, "commit"=>"Submit"}
  User Load (0.5ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
   (0.4ms)  SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 1]]
Completed 500 Internal Server Error in 77ms

SystemStackError - stack level too deep:
  actionpack (4.1.1) lib/action_dispatch/middleware/reloader.rb:79:in `'

A Post model looks like this:

# == Schema Information
#
# Table name: posts
#
#  id         :integer          not null, primary key
#  status     :string(255)
#  title      :string(255)
#  date       :datetime
#  image      :string(255)
#  body       :text
#  created_at :datetime
#  updated_at :datetime
#  user_id    :integer
#  ancestry   :string(255)
#  file       :string(255)
#

class Post < ActiveRecord::Base
  has_ancestry
  belongs_to :user
  resourcify

  mount_uploader :photo, ImageUploader
  mount_uploader :file, FileUploader
end

My PostsController looks like this:

  def create
    @post = current_user.posts.new(post_params)

    respond_to do |format|
      if @post.save
        format.html { redirect_to @post, notice: 'Post was successfully created.' }
        format.json { render :show, status: :created, location: @post }
      else
        format.html { render :new }
        format.json { render json: @post.errors, status: :unprocessable_entity }
      end
    end
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_post
      @post = Post.find(params[:id])
    end

    # Never trust parameters from the scary internet, only allow the white list through.
    def post_params
      params.require(:post).permit(:status, :title, :date, :photo, :body, :parent_id)
    end

This is what my form partial looks like:

<%= simple_form_for @post do |f| %> 
    <%= f.error_notification %>

    <%= f.input :parent_id, as: :hidden %>

    <% if can? :manage, @post %>
      <%= f.input :status, collection: Status.all %>
    <% end %>       

    <%= f.input :title %><br />
    <%= f.input :date %><br />      
    <%= f.input :photo %><br />
    <%= f.input :body %><br />      

  <%= f.button :submit %>

<% end %>

Any ideas on what may be causing this error?

Update 1:

When I create a post without a file being uploaded, it creates fine, as can be seen by the log below:

Started POST "/posts" for 127.0.0.1 at 2014-08-28 06:34:50 -0500
Processing by PostsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"daUAvh6w4dCH3sswJ6dckYRJjzq2EMfiQZ/uiD/0ADg=", "post"=>{"status"=>"confirmed", "title"=>"Test Post", "body"=>"Does this work at all."}, "commit"=>"Submit"}
  User Load (0.3ms)  SELECT  "users".* FROM "users"  WHERE "users"."id" = 1  ORDER BY "users"."id" ASC LIMIT 1
   (0.4ms)  SELECT COUNT(*) FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL)))  [["user_id", 1]]
   (0.4ms)  BEGIN
  SQL (2.2ms)  INSERT INTO "posts" ("body", "created_at", "status", "title", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"  [["body", "Does this work at all."], ["created_at", "2014-08-28 11:34:50.886549"], ["status", "confirmed"], ["title", "Test Post"], ["updated_at", "2014-08-28 11:34:50.886549"], ["user_id", 1]]
   (0.8ms)  COMMIT
Redirected to http://localhost:3000/posts/2
Completed 302 Found in 83ms (ActiveRecord: 4.1ms)

So it seems the culprit is actually in Carrierwave/Fog/Strong Parameters somewhere in there.

Update 2:

Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.1.1'

group :assets do
  gem 'sass-rails', '~> 4.0.3'
  gem 'uglifier', '>= 1.3.0'
  gem 'coffee-rails', '~> 4.0.0'
  gem "font-awesome-rails"
  gem 'bootstrap-sass', '~> 3.2.0'
  gem 'autoprefixer-rails'
end

group :development do
    gem 'annotate', github: 'ctran/annotate_models'
    gem 'sextant'
  gem "quiet_assets", ">= 1.0.2"
  gem 'better_errors', '~> 1.1.0'
  gem 'binding_of_caller', '~> 0.7.2'
    gem 'meta_request'
    gem 'execjs'
    gem 'therubyracer'  
  gem "letter_opener"
  gem 'bullet'   
  gem 'rack-mini-profiler'     
  gem 'guard-rails'
  gem 'rb-fchange', :require=>false
  gem 'rb-fsevent', :require=>false
  gem 'rb-inotify', :require=>false
  gem 'guard-livereload', '~> 2.3.0', :require=>false
  gem 'rack-livereload', '~> 0.3.15'
end

group :production do
  gem 'rails_12factor'
end

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc
gem 'spring',        group: :development
gem 'devise', '~> 3.2.4'
gem 'thin'
gem 'pg'
gem 'cancancan', '~> 1.8.2'
gem 'rolify'
gem "rmagick"
gem "mini_magick"
gem 'carrierwave', '~> 0.10.0'
gem "fog", "~> 1.3.1"
gem 'figaro', '~> 0.7.0'
gem 'geocoder', '~> 1.2.2'
gem 'social-share-button', '~> 0.1.6'
gem 'ancestry', '~> 2.1.0'
gem "simple_form"

Update 3:

So it seems that this particular Stack Level Too Deep Error has been fixed, but the problem has just moved. I have created a new SO question here - Exconn::Errors::SocketError in file upload via Carrierwave and Fog

Community
  • 1
  • 1
marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • it's happening when the post successfully saves or fails or both? – dax Aug 28 '14 at 11:26
  • The post doesn't successfully save. It seems to roll it back. Edit 1: It seems that if I don't attach a file, then the post is successfully created. It is just when I do try to attach a file, that it does this it seems. Going to update the questions. – marcamillion Aug 28 '14 at 11:34
  • can you post your gemfile? – dax Aug 28 '14 at 12:05

2 Answers2

2

Try this:

in your gemfile, change gem "rmagick" to

gem 'rmagick', :require => 'RMagick'

from https://github.com/carrierwaveuploader/carrierwave/issues/1330

Community
  • 1
  • 1
dax
  • 10,779
  • 8
  • 51
  • 86
  • So it seems that got rid of that error, but now I have another error. I am going to create a new SO question and update it here with that new error. Can you take a look when I link it up? – marcamillion Aug 28 '14 at 13:48
  • Here is the new question - http://stackoverflow.com/questions/25550841/exconnerrorssocketerror-in-file-upload-via-carrierwave-and-fog – marcamillion Aug 28 '14 at 14:06
1

Problem is with your database. You are setting strong parameter and mounting uploader for photo but your database have column with name image. Try change column name to photo would solve your issue. Also rmagick require if you are doing any resizing stuff.

Dipak Gupta
  • 7,321
  • 1
  • 20
  • 32
  • It was the rmagick issue, it seems. That `photo` and `image` stuff is correct on my side. I did a lot of renaming and migrations. So anything you see in the question, was just an oversight in my copying. But the column in the db and the code reference match. I fixed it with dax's suggestion, but now I am getting another error. I am going to create a new SO question for that, and paste it here. – marcamillion Aug 28 '14 at 13:49
  • Here is the new question - http://stackoverflow.com/questions/25550841/exconnerrorssocketerror-in-file-upload-via-carrierwave-and-fog – marcamillion Aug 28 '14 at 14:07