Ruby on rails render file in multiple views -
this question has answer here:
i want return same generic invalid page if user not have access page. want make use of invalid page several different views.
how can render page without creating them in every view?
yes, can create other controller , redirect pages, want url in browser same page person trying access. want render page not redirect.
you're going create static page, we'll call invalid.html.erb
, place in static_pages
directory (or maintain static pages app). make sure create route in routes.rb
well:
get 'static_pages/invalid' => 'static_pages#invalid'
then, in application_controller.rb
file, you're going use rescue_from helper call custom method handle error:
rescue_from user::notauthorized, :with => :invalid def invalid redirect_to 'static_pages_invalid_path' end
that's pretty it. read more @ ruby guides.
Comments
Post a Comment