Dynamic_Matchers.Rb:55:In 'Method_Missing': Undefined Method 'Migration_Error=' for Activerecord::Base:Class (Nomethoderror)

Undefined method raise_in_transactional_callbacks=' for ActiveRecord::Base:Class (NoMethodError)

Your config/application.rb has the following line:

config.active_record.raise_in_transactional_callbacks = true

This is not a valid configuration value in your version of Rails. You will need to delete it or comment it out to continue.


Note: this error and the one that preceded it are indicative of an incomplete Rails version change. If you are in the early stages of a tutorial, you might seriously consider restarting your application using your preferred version of Rails from the very start. This will help you avoid this type of error until you are more familiar with the technology.

I can't make Active Record simple query

I had this snippet in my ~/.irbrc

203   # instead of User.find(...) you can do user(...)
204 # without arguments it only returns the model class
205 # based on http://www.clarkware.com/blog/2007/09/03/console-shortcut
206 # Dir.glob( File.join(Dir.pwd, *%w<app models ** *.rb>) ).map { |file_name|
207 # table_name = File.basename(file_name).split('.')[0..-2].join

I commented all the block and now it works. Well, I copied that file and never have understood it.

Would I need to undo a rails generate scaffold after I undo a db:migrate?

First you would need to rollback the changes from db.
Assuming that the migration generated for Miropost is the latest migration in your db.

Just run

rake db:rollback ## This will drop the table miroposts

After this destroy the existing scaffold by :

rails destroy scaffold Miropost content:string user_id:integer

Then all you need to do is to recreate the scaffold with correct spelling and run rake db:migrate

Rails dynamic foreign key for has_many relationship

Ok so let me correct that: this is not possible, and even if in a utopian world it was or you found a workaround for this, it is certainly not correct.

What you are in fact looking for is a mix between inheritance (STI or Single Table Inheritence in Rails) and polymorphism.

How can you implement this the right way?

You have a user model, Students and Mentors ar both Users so they will both inherit for this model.

class User < ActiveRecord::Base
end

class Student < User
end

class Mentor < User
end

What does it implies? Well it implies that the User model holds (without you doing anything else) a field type wich will either contain 'Student' or 'Mentor' or nothing depending on how you initialize your object:

user = User.create()
student = Student.create()
mentor = Mentor.create()

Now, your Request can either belong to a Student or to a Mentor. So here you could set a polymorphic association like so:

class Student < User
has_many :requests, as: :owner
end

class Mentor < User
has_many :requests, as: :owner
end

class Request < ActiveRecord::Base
belongs_to :owner, polymorphic: true
end

Now you can write:

student.requests
mentor.requests
request.owner


Related Topics



Leave a reply



Submit