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 8226063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:38:01+00:00 2026-06-07T15:38:01+00:00

ruby 1.9.2p290 rails 3.1.1 How to create a html element from controller in SLIM

  • 0
  • ruby 1.9.2p290
  • rails 3.1.1

How to create a html element from controller in SLIM templates?

I will explain:

In my views, I want to change the “h1” html tag by some conditions.

But I want to put the logic inside controller.

case params[:controller] when "recipes", "chefs"
    case params[:action] when "show", "index"
      @h_number = "h2"
    else
      @h_number ="h1"
    end
  else
    @h_number ="h1"
end

In my SLIM view, I would like something like that:

= @h_number#logo
    = link_to image_tag("image.png"), root_path

Which results in:

<h1 id="logo"><a href="/"><img src="image.png"></a></h2>

or

<h2 id="logo"><a href="/"><img src="image.png"></a></h2>

Is it possible?

Am I clear? Sorry about my english.

  • 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-07T15:38:03+00:00Added an answer on June 7, 2026 at 3:38 pm

    I highly doubt this is possible. But you could always create a helper method to do this

    In your application helper file,

    module ApplicationHelper
        def logo
            num = case params[:controller] when "recipes", "chefs"
              case params[:action] when "show", "index" then 2 end
            end || 1
    
            "<h#{num}>" + link_to(image_tag("image.png"), root_path) + "</h#{num}>"
        end
    end
    

    In your template

    body
      header
        == logo
    

    And your controllers don’t need anything.

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

Sidebar

Related Questions

I'm using Rails 3.0.0 + passenger + apache2 running on Ruby 1.9.2p290 on an
ruby 1.9.2p290 rails 3.1.1 Basically I have two models: CHEFS and RECIPES. class Chef
ruby 1.9.2p290 rails 3.1.1 I have two models: RECIPE and RECIPE_CATEGORY with belongs_to and
Ruby on Rails controllers will automatically convert parameters to an array if they have
I'm running Ruby 1.9.2p290 and Rails 3.1.0.rc5. When I run this regex it matches
Ruby on Rails: I'd like the <%= render 'shared/intro_form' %> to render a form
I wanted to create an online shop using rails and the spree gem (http://spreecommerce.com/).
I am deploying Ruby On Rails apps on an Amazon EC2 cloud server. The
I have an app based on Rails 3 (version Rails 3.1.2 ) and ruby
I am very new to Ruby and Rails. I use rails 3.0.9 and ruby

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.