ruby on rails - How do I create a link (or button) that will execute an Application Helper method? -
i new ruby/rails , trying create links update variable in session. have following method defined in application_helper.rb--
i put here in hopes correct place have can used all views:
module applicationhelper def add_workspace_to_session(workspace_id) session[:workspace_id] = workspace_id end end
in view want create simple link (or button) call helper, passing in workspace id updates session[:workspace_id]
. how make link in view? using link_to? i'm missing something...having routes?
thanks!
if creating button or link should pointed url path not helper method. quick fix add path helper method.
note: have not tested passing parameter.
def add_workspace_to_session(workspace_id, url) session[:workspace_id] = workspace_id url end <%= button_to "store workspace", add_workspace_to_session(workspace_id, root_path), :method => :get %>
Comments
Post a Comment