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

  • Home
  • SEARCH
  • 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 8106533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:29:59+00:00 2026-06-06T00:29:59+00:00

I have a simple controller that was created through a scaffold and has a

  • 0

I have a simple controller that was created through a scaffold and has a “Show” function.

In the view that was created through the scaffold, I have an image that appears only on a certain condition.

I want to set or evaluate the condition in the controller and send it to the view.
I am not sure how to do that or whether this is the correct approach.

  • 1 1 Answer
  • 0 Views
  • 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-06-06T00:30:01+00:00Added an answer on June 6, 2026 at 12:30 am

    The condition should generally be dealt with in the view file using erb, or haml. If you update your question with the condition, then I’ll see about updating my answer to reflect it. For now, I’ll use a common condition.

    Say you only want to show an image if an object is featured. Let’s imagine there is a featured field in your object that acts as a flag (1,0).

    If this object is say an Article, we can then check the condition in the view file. The controller would obtain the article from the model:

    -# articles_controller show action 
    @article = Article.find(params[:id])
    

    ..

    -# views/articles/show.html.erb
    <% if @article.featured? %>
      // show image here
    <% end %>
    

    Remember this is an example condition that is not necessarily correct. It is just to illustrate my initial approach.

    I wouldn’t suggest you use javascript to hide/show depending on this condition, because you are then putting your logic in javascript, when it can be easily managed from within your view files.

    If the condition is complex, you would then move it to the model, and perform something like:

    if @article.some_complex_condition?
    

    ..rather than having that complex condition in your controller file. This allows you to reuse the condition away from the specific controller and makes it more testable.

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

Sidebar

Related Questions

I have a simple Controller that looks like this:- @Controller @RequestMapping(value = /groups) public
I have a number of simple controller classes that use Doctrine's entity manager to
I have a simple controller called list_controller with an index that basically does def
I have a simple form in python + pylons that submits to a controller.
I have a simple UserControl for database paging, that uses a controller to perform
I have a very simple RootView Controller ->Detail View Controller, to display a list
I have a simple unsubscribe function in my Unsubscribed controller. if ($this->Unsubscribe->save($this->data['Unsubscribes'])) { //
I wanted to make a simple chart of users that have been created in
I currently have a simple app that includes user authentication through devise and a
So I have a simple post model that has_many tags :through post_tags. This allows

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.