How to remove validation using instance_eval clause in Rails?

I found a solution, not sure how solid it is, but it works well in my case. @aVenger was actually close with his answer. It’s just that the _validators accessor contains only information used for reflection, but not the actual validator callbacks! They are contained in the _validate_callbacks accessor, not to be confused with _validations_callbacks. … Read more

Rails has_one / has_many, dependent option: What values are available?

Docs are available here Looks like the following options are supported: nil – do nothing (default). :destroy – causes all the associated objects to also be destroyed. :delete_all – causes all the associated objects to be deleted directly from the database (so callbacks will not be executed). :nullify – causes the foreign keys to be … Read more

Could not find the association problem in Rails

In the ApplicationForm class, you need to specify ApplicationForms’s relationship to ‘form_questions’. It doesn’t know about it yet. Anywhere you use the :through, you need to tell it where to find that record first. Same problem with your other classes. So # application_form.rb class ApplicationForm < ActiveRecord::Base has_many :form_questions has_many :questions, :through => :form_questions end … Read more

varchar Migration question for Ruby on Rails

The correct format would be t.string :note, :limit => 1000 make sure you are using a version of MySQL(or whichever database) which supports varchars longer than 256 characters. if you want to use a large text block it would be t.text :note See http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/TableDefinition.html for more information

first_or_create vs find_or_create_by

Basically: Foo.where(attributes).first_or_create Is the same as: Foo.find_or_create_by(attributes) #first_or_create is sometimes misunderstood as people expect it to search by the attributes given, but that is not the case. Aka Foo.first_or_create(attributes) Will not search for a foo that satisfies the attributes. It will take the first foo if any are present. It’s useful if the conditions for … Read more

How to rescue model transaction and show the user an error?

def exchange_status_with(address) ActiveRecord::Base.transaction do self.save! address.save! end rescue ActiveRecord::RecordInvalid => exception # do something with exception here end FYI, an exception looks like: #<ActiveRecord::RecordInvalid: Validation failed: Email can’t be blank> And: exception.message # => “Validation failed: Email can’t be blank” Side note, you can change self.save! to save! Alternate solution if you want to keep … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)