The following is set up in my rail app to highlight my current rail link.
& lt; Div class = "env-alt rtl" & gt; & Lt;% = section_link ("Home" ,: Admin = & gt; 'Welcome')%> | & Lt;% If user_signed_in? & Gt%; & Lt;% = section_link ("map" ,: admin = & gt; 'poin')%> | & Lt;% = section_link ("news",: admin => gt; news', ref = & gt; 'home')%> | & Lt;% = section_link ("document",: admin = & gt; 'document',: ref = & gt; 'home')%> | & Lt;% = section_link ("Organization" ,: Administrator = & gt; 'Organization' ,: ref = & gt; 'Home')% & gt; | & Lt;% = section_link ("Dashboard" ,: Admin = & gt; 'Welcome' ,: Action = & gt; 'Dashboard')% & gt; | & Lt;% # = link_to "Sign out", destroy_user_session_path ,: id = & gt; 'Sign-out'% & gt; & Lt;% else% & gt; & Lt;% = link_to "Sign up", new_user_registration_path ,: id = & gt; 'Sign-up'% & gt; | & Lt;% = link_to "sign in", new_user_session_path ,: id = & gt; 'Sign_in'% & gt; & Lt;% end% & gt; & Lt; / Div & gt; I have the following:
DRF Institution_controller_and_action_name @ cert_action_action_action_name @ circuit_controller = controller_name and application_helper. In rb:
def section_link (name, option) action = option [: verb] || 'Index' controller = option [: controller] if action.eql? (@ Current_action) and controller Eql? (@ Current_controller) link_to (name, option, class = & gt; 'youarehere') and link_to (name, option) end end I think everything is fine- Although it's set up properly, it's throwing me this odd error:
/home/syed/work/projects/mapunity/environment/app/views/shared/links/_user.erb Where the line # 2 is shown: No matches match {: controller => "Devise / welcome"} Removed source (around line # 2): 1: & lt; Div class = "env-alt rtl" & gt; 2: & lt;% = section_link ("Home" ,: Admin = & gt; 'Welcome')%> | 3: & lt;% If user_signed_in? & Gt%; 4: & lt;% = section_link ("map" ,: admin = & gt; 'poin')%> | 5: & lt;% = section_link ("news" ,: admin => gt; news', ref = & gt; 'home')%> | Why is it adding automatically: controller = & gt; "Dissatisfied / Welcome"? Any sign of where I am going wrong will be appreciated. thank you in advanced.
Answering my own question can be useful for someone else, let me update my section This will be helpful:
A CSS class to highlight the existing link. Define current My definition looks like this: . Current {font-size: 12pt; Text-decoration: None; } In application_controller.rb , define a first_filter which will set the current controller and action name. def section_link_to (name, name, format), Url_options, html_options = {}) if url_options.is_a? (Hash) verb = url_options [: verb] || (Names, url_options, html_options, class = & gt; 'current') and link_to (name, url_options, html_options), 'index' controller = url_options [: controller] if action.eql? Url_options, html_options) and if url_options.length & gt; 1 controller = url_options.delete ('/') if controller. Are included? ('?') Controller = controller. Split ('?') [0] end controller = 'welcome' if the controller == @ circuit_controller if html_options .has_key? (: Class) css_options = html_options.fetch (: class) css_options & lt; & Lt; 'Current' html_options.merge! ({: Class => css_options}) Other html_options.merge! ({: Class = & gt; 'current'}) end link_to (name, url_options, html_options) and link_to (name, url_options, html_options) end-end In the assistant, I see I am not sure whether the current_controller and current_action are equal to the link that is being provided. If so, then class on that link. Add and Render the current Now I can pass a hash of options either:
<% = Section_link_to "Home" ,: Controller => 'Welcome% & gt; Or use the generated rail:
<% = section_link_to "home", root_path%> & gt;
Comments
Post a Comment