Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6817657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:04:57+00:00 2026-05-26T21:04:57+00:00

I have a partial which is used all over the site. I have an

  • 0

I have a partial which is used all over the site. I have an image in the partial that I want to link to a certain page on all pages except one particular controller action.

1. Is there way to put in the following href without 2 if else sets?…

<a href="#">
  <img src="#" />
</a>

I’m trying to avoid doing this:

<% if (current controller != xyz) %>
  <a href="#">
<% end %>
   <img src="#" />
<% if (current controller != xyz) %>
  </a>
<% end %>

2. How can I actually check which controller called this partial?

The above code is only pseudo code.

PS. I know this isn’t that much repetition, but I’m just using this simplified case as an example. Curious if there’s something in Rails I don’t know about to avoid this.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:04:57+00:00Added an answer on May 26, 2026 at 9:04 pm

    This is exactly what link_to_if is for!

    link_to_if(controller_name == 'xyz', image_tag('src'), 'http://target.com')
    

    This will add the image whether the condition is true or not, and wrap it in the link only when the condition is true. There’s also the related link_to_unless which may be more semantically appropriate in your case.

    Edit: I’ve updated the example above to use the correct code for checking the controller name. There’s a method available in the view, controller_name that returns a lowercase version of the name of your controller. It’s also in the params hash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page which contains a html.RenderPartial, that renders an ASP.NET MVC partial
I have an asp.net page within which I've used several AJAX controls doing partial
I currently have a page which is declared as follows: public partial class MyPage
I have a partial that I want to display in a layout only when
We have the below code (partial code) that is used as part of a
I noticed the docs have: <%= item_counter %> But I have a partial which
I have a partial view which contain JavaScript and Ajax, but does not run
Hi guys i have controller which returns a partial view, the controller is called
I want to program something in both C# and F#. I have partial classes
I have a partial that renders a select box using the following method: <%=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.