开发者

What is this in rails?

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

Seems to be doing alot bu开发者_如何学Pythont where is it....is it part of rails


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜