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
Cannot Install Any Version of Ruby on Mojave - Internal Ranlib Command Failed
How to Inspect What Is the Default Value for Optional Parameter in Ruby's Method
Load Two Ruby Modules/Gems with the Same Name
How to Receive a JSON Object with Rack
How to Install Rails with Jruby
Cocoon Add Association, How to Limit Number of Associations
Ruby: Building a Plot of Function
Difference Between or and || When Setting Variables
How to Reference a Constant in a Yaml with Rails
Rails 3 - How to Set Start Date to Date_Select Method
How to Has_And_Belongs_To_Many Multiple Instances of the Same Model
Protected Sharing Link in Ruby on Rails
Rails Form Object with Virtus: Has_Many Association
Simplify Multiple Nil Checking in Rails
Error When Run Migrations on Heroku, Postgresql with Rails 5