
HOW TO USE:
First add the gem in your Gemfile:
gem 'inherited_resources'
Now Make a Controller, which you want to create, In my case, I'm creating a POST Controller without Scaffold:
so Just make a file name posts_controller.rb
Now, Open Posts Controller Page and Add code there:
class PostsController < ApplicationController
Now the Tricky Part, You don't need to create any
def index Something code.... enddef new Something code....end
def create Something code....end
def edit Something code....end
def update Something code....end
def destory Something code....end
DON'T NEED, Remove this Code and Add Here:
class PostsController < ApplicationController
inherited_resources
def permitted_paramsparams.permit(post: [:title, :content])end
Now Create a MODEL and VIEW as same as you create, That's it.
All the CRUD Action will work auto through Inherited resources Gem.
Note: don't forgot to mention resources :posts in your routes file.
Tags: Ruby on Rails Tutorials, Ruby on Rails Videos, Ruby Gems, Gems Use trick, Ruby code, Rails servers
Comments
Post a Comment