Skip to content

codyrobbins/create-new

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Create New

This Rails plugin makes a create_new method available in ApplicationController which

  • takes the name of an ActiveRecord model and
  • sets an appropriately named instance variable in the controller
  • with a new instance of the model
  • initialized with the attributes in params corresponding to the model name.

Full documentation is at RubyDoc.info.

Example

The following

class UserController < ApplicationController
  def create
    create_new(:user)
  end
end

is the equivalent of

class UserController < ApplicationController
  def create
    @user = User.new(params[:user])
  end
end

Colophon

See also

If you like this gem, you may also want to check out Declarative Find, Save Changes To, or HTTP Error.

Tested with

  • Rails 3.0.5 — 20 May 2011

Contributing

To send patches, please fork on GitHub and submit a pull request.

Credits

© 2011 Cody Robbins. See LICENSE for details.

About

Create a new instance of a Rails model in controller actions in one call.

Resources

License

Stars

Watchers

Forks

Languages