ruby - Globally accessible variable in rails -
i want variable globally accessible whole app. user fill single input field form. saved database , variable accessible anywhere. here have done far.
class applicationcontroller < actioncontroller::base # prevent csrf attacks raising exception. # apis, may want use :null_session instead. protect_from_forgery with: :exception before_action :save_page def save_page @page_name = params[:page_name ] test_page_name = pagename.new test_page_name.name = @page_name if test_page_name.save redirect_to(controller: 'template',action: 'templates') end end end
the form submitted save_page method in applicaitoncontroller , after being saved redirected. because method redirect in case of saved database, giving me problem. how can fix this?
i tried no luck
class applicationcontroller < actioncontroller::base # prevent csrf attacks raising exception. # apis, may want use :null_session instead. protect_from_forgery with: :exception before_action :page_name def save_page @page_name = params[:page_name ] test_page_name = pagename.new test_page_name.name = @page_name if test_page_name.save redirect_to(controller: 'template',action: 'templates') end end def page_name @user_page_name = @page_name end end
but when tried print value of @user_page_name in view got nothing.
class applicationcontroller < actioncontroller::base # prevent csrf attacks raising exception. # apis, may want use :null_session instead. protect_from_forgery with: :exception before_action :page_name def param_page @page_name=params[:page_name] end def save_page param_page test_page_name = pagename.new test_page_name.name = @page_name if test_page_name.save redirect_to(controller: 'template',action: 'templates') end end def page_name param_page @user_page_name = @page_name end end
Comments
Post a Comment