ruby on rails - Add action to scaffold generated controller -


i have created model, view , controller:

$ rails generate scaffold post name:string title:string content:text 

then have added method on post controller:

def fill_default_data   post.fill_default_data end 

but when have open http://localhost:3000/posts/fill_default_data in browser error:

activerecord::recordnotfound in postscontroller#show

couldn't find post id=fill_default_data

it looks rails don't see fill_default_data action , use show method. how can add new method scaffold generated controller?

you should add relevant route config/routes.rb file. if have:

resources :posts 

you should change to:

resources :posts   collection     :fill_default_data   end end 

that generate route can access through /posts/fill_default_data. app accessing show action , filling in "fill_default_data" id.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -