Last active
July 14, 2016 18:33
-
-
Save Circuit8/5c546d0d12a17d114112e7c582e3cfd9 to your computer and use it in GitHub Desktop.
Revisions
-
Circuit8 revised this gist
Jul 14, 2016 . 2 changed files with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ [25] pry(main)> exercise = Exercise.new(:name =>"anything") => #<Exercise:0x0055af50e06870 id: nil, name: "anything", created_at: nil, updated_at: nil, exercise_category_id: nil> [26] pry(main)> exercise.build_image(:file_file_name => "anything") => #<Image:0x0055af50d806f8 id: nil, title: "", imageable_type: "Exercise", imageable_id: nil, position: 1, created_at: nil, updated_at: nil, file_file_name: "anything", file_content_type: nil, file_file_size: nil, file_updated_at: nil> [27] pry(main)> exercise.save! ActiveRecord::RecordInvalid: Validation failed: Image imageable must exist from /home/joshua/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0/lib/active_record/validations.rb:78:in `raise_validation_error' -
Circuit8 created this gist
Jul 14, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ ActiveRecord::RecordInvalid: Validation failed: Image imageable must exist This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ class Exercise < ApplicationRecord has_one :image, :as =>:imageable accepts_nested_attributes_for :image end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ # This is failing describe 'saving image' do context 'with an associated image' do let :exercise do build :exercise end before :each do exercise.build_image(attributes_for(:image)) end it 'should save correctly with an associated image' do expect{ exercise.save! }.to_not raise_error end end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ class Admin::ExercisesController < Admin::BaseController def new @exercise = Exercise.new @exercise.build_image end def create @exercise = Exercise.new(exercise_params) respond_to do |format| if @exercise.save format.html { redirect_to admin_exercises_url, notice: 'Exercise was successfully created.' } else format.html { render :new } end end end private def exercise_params params.require(:exercise).permit(:name, :exercise_category_id, :image_attributes => [:file]) end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ class Image < ApplicationRecord belongs_to :imageable, polymorphic: true end