Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

List all methods related to a model which scaffold creates

Is there a way to list all methods which scaffold creates regarding Ruby on Rails?

Example:

rails generate scaffold user name:string admin:references

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Now, within the controller, the following declaration is possible:

@user = User.new 
@user.admin=current_admin

Now, I want to check where the admin() method comes from – or where it is placed respectively.

I tried to figure out that topic with the help of the following book:
Michael Hartl – Ruby on Rails Tutorial Learn Web Development with Rails

>Solution :

You can use this snippet to find where a specific method is defined (User#admin=) in your case:

User.instance_method(:admin=).source_location

And it will likely return something like this, depending on your Ruby and Ruby on Rails version:

["[...]/3.2.0/gems/activerecord-7.0.6/lib/active_record/associations/builder/association.rb", 111]

Which will tell you that it is a method auto-generated by Ruby on Rails for an association.

The next step would then be to look into the source code of User for a defined association like belongs_to :admin.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading