Monday, 15 February 2010

ruby on rails 4 - Carrierwave is not handling file upload when AR backed object is updated -



ruby on rails 4 - Carrierwave is not handling file upload when AR backed object is updated -

can update action in rails handle file uploads carrierwave? after completing action cannot find record of 'uploaded' image where. in rails console, call, user.small_cover, , next returned not satisfactory: #, @mounted_as=:small_cover>

my update action big show of import slice

... elsif a_nonprofit_staff_member_updates_profile?(organization) @user.update_columns(user_params) flash[:notice] = "you have updated profile successfully." redirect_to user_path(@user.id) ... def user_params params.require(:user).permit(:first_name, :last_name, :email, :password, :organization_id, :bio, :skills, :interests, :position, :user_group, :contact_reason, small_cover: [:original_filename] ) end

i tried using, :small_cover, attribute got error, no name method nil object, unusual me seeing object not nil , not calling a, name, method. packaging submitted parameters correctly?

how 1 upload file using carrierwave when action updating , not creating ar backed object in rails? handling parameters incorrectly

update: here relevant code user model , uploader

class user < activerecord::base has_secure_password validations: false belongs_to :organization has_one :administrated_organization, foreign_key: 'user_id', class_name: 'organization' has_many :sent_messages, class_name: 'privatemessage', foreign_key: 'sender_id' has_many :received_messages, -> {order('created_at desc')}, class_name: 'privatemessage', foreign_key: 'recipient_id' has_many :administrated_projects, through: :administrated_organization, source: :projects has_many :volunteer_requests, class_name: 'volunteerapplication', foreign_key: 'administrator_id' has_many :projects, through: :volunteer_applications, source: :administrator has_many :delegated_projects, class_name: "contract", foreign_key: 'contractor_id' has_many :projects, through: :contracts, source: :contractor has_many :requests_to_volunteer, class_name: 'volunteerapplication', foreign_key: 'applicant_id' has_many :projects, through: :volunteer_applications, source: :applicant has_many :assignments, class_name: "contract", foreign_key: 'volunteer_id' has_many :projects, through: :contracts, source: :volunteer has_many :questions validates_presence_of :email, :password, :first_name, :last_name, :user_group validates_uniqueness_of :email mount_uploader :small_cover, smallcoveruploader before_create :generate_token end class smallcoveruploader < carrierwave::uploader::base end

schema:

activerecord::schema.define(version: 20140619170102) create_table "contracts", force: true |t| t.integer "contractor_id" t.integer "volunteer_id" t.boolean "active" t.datetime "created_at" t.datetime "updated_at" t.integer "project_id" t.boolean "dropped_out" t.boolean "complete" t.boolean "incomplete" t.boolean "work_submitted" end create_table "conversations", force: true |t| t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" t.integer "volunteer_application_id" t.integer "contract_id" end create_table "organizations", force: true |t| t.string "name" t.datetime "ruling_year" t.text "mission_statement" t.string "guidestar_membership" t.string "ein" t.string "street1" t.string "street2" t.string "city" t.integer "state_id" t.string "zip" t.integer "ntee_major_category_id" t.string "funding_method" t.integer "user_id" t.string "cause" t.string "state_abbreviation" t.text "goal" t.string "contact_number" t.string "contact_email" t.string "budget" end create_table "private_messages", force: true |t| t.integer "sender_id" t.integer "recipient_id" t.string "subject" t.text "body" t.datetime "created_at" t.datetime "updated_at" t.integer "project_id" t.integer "conversation_id" end create_table "projects", force: true |t| t.string "title" t.text "description" t.string "skills" t.string "causes" t.datetime "deadline" t.datetime "created_at" t.datetime "updated_at" t.integer "user_id" t.integer "organization_id" t.integer "estimated_hours" t.string "state" end create_table "questions", force: true |t| t.integer "user_id" t.string "title" t.text "description" t.datetime "created_at" t.datetime "updated_at" end create_table "users", force: true |t| t.integer "organization_id" t.string "first_name" t.string "last_name" t.string "email" t.string "interests" t.string "skills" t.string "street1" t.string "street2" t.string "city" t.integer "state_id" t.integer "phone_number" t.string "zip" t.boolean "organization_administrator" t.boolean "organization_staff" t.boolean "volunteer" t.datetime "created_at" t.datetime "updated_at" t.string "password_digest" t.string "position" t.integer "project_id" t.string "time_zone" t.text "bio" t.string "contact_reason" t.string "organization_role" t.boolean "nonprofit" t.string "type" t.string "user_group" t.string "state_abbreviation" t.string "new_password_token" t.integer "profile_progress_status" t.string "small_cover" end create_table "volunteer_applications", force: true |t| t.integer "user_id" t.integer "project_id" t.boolean "accepted" t.boolean "rejected" t.datetime "created_at" t.datetime "updated_at" t.integer "applicant_id" t.integer "administrator_id" end end

uploader

class smallcoveruploader < carrierwave::uploader::base end

you should seek separately like:

@user.small_cover.update(cover_params)

i guess association belongs_to :small_cover

you'll need user sec strong parameter method (here called cover_params). means you'll need adapt params.

ruby-on-rails-4 carrierwave

No comments:

Post a Comment