I am very new to programming and I am trying to use paperclip to add a user photo to my user posts. Records can be created from the new recording form without the string <% = f.file_field: photo%> and redirected correctly and saves the record in the database. However, when it is included in save, it wants to redirect to create.html.erb instead of the user path and does not save the new record. It also does not display any errors. I updated the users table with the fields photo_file_name, photo_content_type and: photo_file_size. In addition, I run windows if this is any help.
Model:
class User < ActiveRecord::Base
has_many :venues
has_many :reviews
has_attached_file :photo,
:styles => {
:medium => "300x300>",
:thumb => "100x100>" }
end
Controller:
class UsersController < ApplicationController
def index
@users = User.all
end
def new
@user = User.new
end
def create
@user = User.create(params[:user])
if @user.save
flash[:notice] = 'User added'
redirect_to users_path
else
@user.save
end
end
def show
@user = User.find(params[:id])
end
end
View:
<% form_for (@user, :html => { :multipart => true }) do |f| %>
<p>username: <br>
<%= f.text_field :username %></p>
<p>password: <br>
<%= f.text_field :password %></p>
<p>photo: <br>
<%= f.file_field :photo %></p>
<%= submit_tag %>
<% end %>
Any help is much appreciated!
What is shown in the development log:
UsersController # create ( 127.0.0.1 2011-01-12 22:05:56) [POST] : { "" = > { "" = > #, " " = > "nghjhg", "password" = > "ghjghj" }, "commit" = > " ", "Authenticity_token" = > "IlacpnqsC/Ij + 41bx8tN4obOWPgirMx810l/WvohN68 =" } [paperclip] -% wx% h "C:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png [0]" 2 > NUL [paperclip] :
:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png "" . > [paperclip] define -format % WX% "C:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png [0]" 2 > NUL [paperclip] :
:/Users/Home/AppData/Local/Temp/stream110112-5292-2yorcw-0.png "" . > / users/create 157ms (: 4, DB: 0) | 200 OK [HTTP:///]