Terence Devine

Joined

230 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Migration Issue caused Heroku to fail.

I have an application on Heroku that uses the Paperclip gem that recently had some issues - and I'm not 100% sure on what it was that caused it. I have the application working locally (including the image upload) - but I get an 'Application Error' page on the heroku url, and when I try to access the heroku console with heroku run rails c it gets an error of:


/app/vendor/bundle/ruby/2.0.0/gems/activerecord-4.2.1/lib/active_record/dynamic_matchers.rb:26:in 'method_missing': undefined method '_image_post_process_callbacks' for #<Class:0x007f8aaf5d2fa0> (NoMethodError)

A little background on the issue - another developer was working on creating an image upload model - which was named 'Images' - which I think caused problems with Paperclip, and wouldn't allow me to run a Rails migration. When I tried it said there was an issue with the 'Images' table, so after finding a similar situation online, I commented out the body of the 'def change' within the create_images migration - which now looks like so:


class CreateImages < ActiveRecord::Migration
def change
# create_table :images do |t|
# t.attachment :file
# end
end
end

I then ran another migration - started my server locally and everything was working. I then pushed my changes to heroku, did a rake db:migrate for good luck - and the heroku url is still showing 'Application Error'

If anyone has any idea of possible causes of these issues, it would be greatly appreciated! Thanks for reading!

Posted in Rails Paperclip Gem - save parent model ID to path

I created a question on StackOverflow - but it hasn't gotten any attention as of yet, so I thought I'd share it here.

If you have any suggestions at all, feel free to share!

http://stackoverflow.com/questions/34164620/rails-paperclip-gem-save-parent-model-id-to-path

Thanks!

Posted in Flexible Nested Attributes

I'm finally getting back around to this - and am looking more into adding scope into the association, but am new to the topic and am having trouble finding much help besides active record documentation.

Would this type of scope be added to each of the different models that makes up the 'Content Blocks'? Sorry - just new to scope and not sure where to start!?

Thanks again!

Posted in Flexible Nested Attributes

Yes - Cocoon calls them "nested forms" - but the difference I have here is that I need to have multiple models that are all combined / contained within one larger group (content blocks)... which is why I decided to throw the word 'Flexible' in there!

I haven't had a chance to watch this yet (bouncing between tasks at work) but does this tutorial give some insight on how to handle this sort of task? Seems the 'merge' might be exactly what I'm looking for to combine these models.

https://gorails.com/episodes/named-scopes-with-activerecord-merge

I'll be sure to watch this screencast once I'm back from work, but wanted to make a post while it was fresh in my mind. Thanks again!

Posted in Flexible Nested Attributes

sorry for the multiple posts - I keep getting errors whenever I try to post / comment on threads!?

Posted in Flexible Nested Attributes

I'm working on a practice "Magazine" application, that has Issues with nested attributes of Articles, which has multiple nested attributes that are Content Blocks, which can be one of several types of Models (ie: Text Field, Image Upload, Image Gallery, etc).

Example
Issue

  • Article
  • - Content Block ( Text Field )
  • - Content Block ( Image )
  • - Content Block ( Text Field )
  • - Content Block ( Image Gallery )

In my head I've been referring to these Content Blocks as 'Flexible Nested Attributes'... not sure if theres any proper terminology for this?

I am using the Cocoon Gem for this.

I tried adding 'order_number' to Models, and just adding the two 'link_to_add_association' links as well as the respective fields for the form (see below) - and then ordering the two content types in the controller (see below-er)... which works, except for when I go to edit the form, and it orders all the items by their content type.

Do you know if the Cocoon gem can be used in this way? Or is there another gem I should be using (such as ActiveForm Gem)? Or if this is all wrong and maybe I should approach it some other way!?

Any help is greatly appreciated! Thanks!

= simple_form_for @recipe, html: { multipart: true } do |f|
    - if @recipe.errors.any?
        #errors
            %p
                = @recipe.errors.count
                Prevented this recipe from saving
            %ul
                - @recipe.errors.full_messages.each do |message|
                    %li= msg

    = f.input :title
    = f.input :description
    = f.input :image

    %h3 Contents
    #contents
        = f.simple_fields_for :images do |image|
            = render 'image_fields', f: image
        = f.simple_fields_for :textarea do |textarea|
            = render 'textarea_fields', f: textarea
        = link_to_add_association 'Add image', f, :images
        = link_to_add_association 'Add textarea', f, :textarea

    = f.button :submit
    def show
        @contents = @recipe.textarea + @recipe.images
        @contents = @contents.sort_by(&:order_number)
    end

Posted in Flexible Nested Attributes

I'm working on a practice "Magazine" application, that has Issues with nested attributes of Articles, which has multiple nested attributes that are Content Blocks, which can be one of several types of Models (ie: Text Field, Image Upload, Image Gallery, etc).

Example
Issue

  • Article
  • - Content Block ( Text Field )
  • - Content Block ( Image )
  • - Content Block ( Text Field )
  • - Content Block ( Image Gallery )

In my head I've been referring to these Content Blocks as 'Flexible Nested Attributes'... not sure if theres any proper terminology for this?

I am using the Cocoon Gem for this.

I tried adding 'order_number' to Models, and just adding the two 'link_to_add_association' links as well as the respective fields for the form (see below) - and then ordering the two content types in the controller (see below-er)... which works, except for when I go to edit the form, and it orders all the items by their content type.

Do you know if the Cocoon gem can be used in this way? Or is there another gem I should be using (such as ActiveForm Gem)? Or if this is all wrong and maybe I should approach it some other way!?

Any help is greatly appreciated! Thanks!

= simple_form_for @recipe, html: { multipart: true } do |f|
    - if @recipe.errors.any?
        #errors
            %p
                = @recipe.errors.count
                Prevented this recipe from saving
            %ul
                - @recipe.errors.full_messages.each do |message|
                    %li= msg

    = f.input :title
    = f.input :description
    = f.input :image

    %h3 Contents
    #contents
        = f.simple_fields_for :images do |image|
            = render 'image_fields', f: image
        = f.simple_fields_for :textarea do |textarea|
            = render 'textarea_fields', f: textarea
        = link_to_add_association 'Add image', f, :images
        = link_to_add_association 'Add textarea', f, :textarea

    = f.button :submit
    def show
        @contents = @recipe.textarea + @recipe.images
        @contents = @contents.sort_by(&:order_number)
    end
logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.