firstruby

Master ruby with us

resource_controller plugin with different associated model

Posted by firstruby on December 17, 2009

If we use resource_controller gem/plugin in Ruby on Rails application, then as per the default configuration, it takes the associated Model name with respective Controller name as,

in app/controllers/posts_controller.rb file,
class PostsController < ResourceController::Base
resource_controller
end

This above configuration will find for Post Model. But if you want to change it to associate it to different model as ‘Comment’ Model, then you can do it as,

class PostsController < ResourceController::Base
resource_controller


private
def model_name
'comment' # Model Name
end
end

Ref. URL – http://jamesgolick.com/resource_controller/rdoc/files/__/README_rdoc.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: