Matt Elhotiby
Matt Elhotiby

Reputation: 44086

What is this in rails?

    create! do |success, failure|      
      success.html { redirect_to admin_blogs_path }
    end

Seems to be doing alot but where is it....is it part of rails

Upvotes: 0

Views: 121

Answers (2)

Ryan Bigg
Ryan Bigg

Reputation: 107738

Indeed as Matt's comment points out, this functionality is provided by Jose Valim's inherited_resources gem. This gem provides people with a way of drastically cutting down on the repetition in CRUD controllers by abstracting all the standard crap away into a gem.

Upvotes: 2

tadman
tadman

Reputation: 211740

Presuming this is being called in the context of an ActiveRecord model, this doesn't appear to be core. The function of create! is to either successfully create the record or throw an exception if a failure occurs. As such, the failure block wouldn't execute.

What it might be is a wrapper around the ActiveRecord object used by an ActionController instance and handles states accordingly. You may want to see where this method is defined in order to get a better sense of what it's doing.

One way to track down mystery methods is this:

raise method(:create!).source_location.inspect

You'll get an array that lists the source file and source line if it can be resolved.

Upvotes: 3

Related Questions