signs-not-to-be-a-programmer-sitting

Rails : Mass assignment with ids in seeds.rb | PG::UniqueViolation: ERROR

Looks like you can mass-assign records into ActiveRecord models without any problem like

Category.create([
                    { parent_id: 1, name: 'Computer Science', description: 'Readable via Electronic devices.' },
                    { parent_id: 1, name: 'Electronics' },
                    { parent_id: 1, name: 'Law' },
                    { parent_id: 1, name: 'Social' }
                ])

But you cannot do like Continue reading

tableinheritanceheirarchy

Rails : Formtastic : Single Table Inheritance : Issues and solution

I have been using Formtastic from the beginning and then some feature changes came across my application. I had a model called `DrugTest` then I also needed to implement additional drugtest (hair test and alcohol test). So I thought STI would be a perfect match to my scenario.

I created two classes `AdditionalHairDrugTest` and `AdditionalAlcoholDrugTest` derived from the model `DrugTest`

# == Schema Information
#
# Table name: drug_tests
# type :string
# ...
class AdditionalAlcoholDrugTest < DrugTest
 belongs_to :pact
 belongs_to :user
 default_scope -> {where(type: :AdditionalAlcoholDrugTest)}

 def is_additional?
   true
 end
end

Now I encountered this error Continue reading

Heroku : Rails : Compiled slug size: 325.0MB is too large

What is slug?

Slugs are compressed and pre-packaged copies of your application optimized for distribution to thedyno manager. When you git push to Heroku, your code is received by the slug compiler which transforms your repository into a slug. Scaling an application then downloads and expands the slug to a dyno for execution.

What is this error about?

It means you code base is huge and compressing it should not exceed size 300 MB; Continue reading

Ruby : Unexpected error : Got surprised :: unexpected ‘+’, expecting keyword_end

Today I stumbled upon something strange in RUBY,

if @user
  content_tag(:span, class: "post-editer") do
    link_tag "#" do
      content_tag(:i, "", class: "fa fa-cog")
    end +
        get_dropdown_option
  end
else
  "".html_safe
end

ruby_error

/home/john/projects/thepact/app/helpers/pact_profile_page_helper.rb:240: syntax error, unexpected '+', expecting keyword_end

Extracted source (around line #240):
238
239
240
241
242
243
 
 link_tag "#" do
 content_tag(:i, "", class: "fa fa-cog")
 end +
 get_dropdown_option
 end
 else

Solution:

content_tag(:span, class: "post-editer") do
  link_markup = link_tag "#" do
    content_tag(:i, "", class: "fa fa-cog")
  end
  link_markup + get_dropdown_option
end

Amazon S3 : Carrier Wave : Error : The difference between the request time and the current time is too large.

Error:  Excon::Errors::Forbidden

You have sometime faced this error which you can see in the server log in development or any environment. This mainly concerns with Amazon S3 server or any other servers you rely upon for APIs.

Main Reason:

  • You have changed your system Date – Time by any means
  • You use Virtual Machine to run your operating system in which your development environment run and you have resumed the system from suspension after a while.
  • Your server Date – Time is not configured properly if you have your own server locally (Physically)

Continue reading