Correct format for writing conditionals in ruby and then converting output into string using string interpolation inside HAML tagHow to write if-condition in Haml?Rendering haml partials takes a long time… why?Rendering Haml file in a javascript response with railsHow can I pass instance variables to a HAML template on the command line?After installing vim-rails plugin I got problems with HAML indentationGetting a HAML button_to work with twitter bootstraprails form helper without break lineRuby on Rails 4 Haml inline link_to interpolated external website urlHow to render html file as hamlSyntax highlighting issue on multiline code in Sublime Text 3 (Ruby on Rails & Haml)

How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?

Confusion about capacitors

Options leqno, reqno for documentclass or exist another option?

Where does the labelling of extrinsic semiconductors as "n" and "p" come from?

Python "triplet" dictionary?

Is GOCE a satellite or aircraft?

How to set the font color of quantity objects (Version 11.3 vs version 12)?

What does 「再々起」mean?

Asahi Dry Black beer can

Can a creature tell when it has been affected by a Divination wizard's Portent?

Pulling the rope with one hand is as heavy as with two hands?

Find the coordinate of two line segments that are perpendicular

Build a trail cart

Reverse the word in a string with the same order in javascript

Does the EU Common Fisheries Policy cover British Overseas Territories?

Need help understanding harmonic series and intervals

How to create an ad-hoc wireless network in Ubuntu

Help, my Death Star suffers from Kessler syndrome!

Is thermodynamics only applicable to systems in equilibrium?

How does a Swashbuckler rogue "fight with two weapons while safely darting away"?

Are Boeing 737-800’s grounded?

Was it really necessary for the Lunar Module to have 2 stages?

Can fracking help reduce CO2?

Why do TACANs not have a symbol for compulsory reporting?



Correct format for writing conditionals in ruby and then converting output into string using string interpolation inside HAML tag


How to write if-condition in Haml?Rendering haml partials takes a long time… why?Rendering Haml file in a javascript response with railsHow can I pass instance variables to a HAML template on the command line?After installing vim-rails plugin I got problems with HAML indentationGetting a HAML button_to work with twitter bootstraprails form helper without break lineRuby on Rails 4 Haml inline link_to interpolated external website urlHow to render html file as hamlSyntax highlighting issue on multiline code in Sublime Text 3 (Ruby on Rails & Haml)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am fixing a bug in a ruby on rails open source project at the front end of the project. I am a newbie to ruby on rails, HAML etc. The following line of code is giving me a lot of trouble.



I am wondering what would be correct way to format this. Further, is there a way to write a helper function to turn the conditionals into a function call? Any help will be appreciated.



I have tried several formats but the devs want me to break up the if-else into several lines. I am unable to make that work.



6: %strong =
7: "#{
8: - if @enterprise.is_primary_producer
9: = t('.producer_profile')
10: - else
11: = t('.profile')



I expect the view to be rendered but instead I get syntax errors.










share|improve this question






























    0















    I am fixing a bug in a ruby on rails open source project at the front end of the project. I am a newbie to ruby on rails, HAML etc. The following line of code is giving me a lot of trouble.



    I am wondering what would be correct way to format this. Further, is there a way to write a helper function to turn the conditionals into a function call? Any help will be appreciated.



    I have tried several formats but the devs want me to break up the if-else into several lines. I am unable to make that work.



    6: %strong =
    7: "#{
    8: - if @enterprise.is_primary_producer
    9: = t('.producer_profile')
    10: - else
    11: = t('.profile')



    I expect the view to be rendered but instead I get syntax errors.










    share|improve this question


























      0












      0








      0








      I am fixing a bug in a ruby on rails open source project at the front end of the project. I am a newbie to ruby on rails, HAML etc. The following line of code is giving me a lot of trouble.



      I am wondering what would be correct way to format this. Further, is there a way to write a helper function to turn the conditionals into a function call? Any help will be appreciated.



      I have tried several formats but the devs want me to break up the if-else into several lines. I am unable to make that work.



      6: %strong =
      7: "#{
      8: - if @enterprise.is_primary_producer
      9: = t('.producer_profile')
      10: - else
      11: = t('.profile')



      I expect the view to be rendered but instead I get syntax errors.










      share|improve this question
















      I am fixing a bug in a ruby on rails open source project at the front end of the project. I am a newbie to ruby on rails, HAML etc. The following line of code is giving me a lot of trouble.



      I am wondering what would be correct way to format this. Further, is there a way to write a helper function to turn the conditionals into a function call? Any help will be appreciated.



      I have tried several formats but the devs want me to break up the if-else into several lines. I am unable to make that work.



      6: %strong =
      7: "#{
      8: - if @enterprise.is_primary_producer
      9: = t('.producer_profile')
      10: - else
      11: = t('.profile')



      I expect the view to be rendered but instead I get syntax errors.







      ruby-on-rails-3 if-statement haml string-interpolation






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 19:15







      Syed Usama Amer

















      asked Mar 22 at 18:19









      Syed Usama AmerSyed Usama Amer

      33




      33






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Something like this?



          %strong
          - if @enterprise.is_primary_producer
          = t('.producer_profile')
          - else
          = t('.profile')


          Personally, I would do something like:



          - t_key = @enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          %strong= t(t_key)


          If you want to move this to a helper, just define it somewhere like in application_helper.rb



          def some_name_for_the_method(enterprise)
          t_key = enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          I18n.t(t_key)
          end


          and on the view



          %strong= some_name_for_the_method(@enterprise)





          share|improve this answer























          • Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

            – Syed Usama Amer
            Apr 1 at 20:18











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305674%2fcorrect-format-for-writing-conditionals-in-ruby-and-then-converting-output-into%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Something like this?



          %strong
          - if @enterprise.is_primary_producer
          = t('.producer_profile')
          - else
          = t('.profile')


          Personally, I would do something like:



          - t_key = @enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          %strong= t(t_key)


          If you want to move this to a helper, just define it somewhere like in application_helper.rb



          def some_name_for_the_method(enterprise)
          t_key = enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          I18n.t(t_key)
          end


          and on the view



          %strong= some_name_for_the_method(@enterprise)





          share|improve this answer























          • Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

            – Syed Usama Amer
            Apr 1 at 20:18















          0














          Something like this?



          %strong
          - if @enterprise.is_primary_producer
          = t('.producer_profile')
          - else
          = t('.profile')


          Personally, I would do something like:



          - t_key = @enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          %strong= t(t_key)


          If you want to move this to a helper, just define it somewhere like in application_helper.rb



          def some_name_for_the_method(enterprise)
          t_key = enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          I18n.t(t_key)
          end


          and on the view



          %strong= some_name_for_the_method(@enterprise)





          share|improve this answer























          • Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

            – Syed Usama Amer
            Apr 1 at 20:18













          0












          0








          0







          Something like this?



          %strong
          - if @enterprise.is_primary_producer
          = t('.producer_profile')
          - else
          = t('.profile')


          Personally, I would do something like:



          - t_key = @enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          %strong= t(t_key)


          If you want to move this to a helper, just define it somewhere like in application_helper.rb



          def some_name_for_the_method(enterprise)
          t_key = enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          I18n.t(t_key)
          end


          and on the view



          %strong= some_name_for_the_method(@enterprise)





          share|improve this answer













          Something like this?



          %strong
          - if @enterprise.is_primary_producer
          = t('.producer_profile')
          - else
          = t('.profile')


          Personally, I would do something like:



          - t_key = @enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          %strong= t(t_key)


          If you want to move this to a helper, just define it somewhere like in application_helper.rb



          def some_name_for_the_method(enterprise)
          t_key = enterprise.is_primary_producer ? '.producer_profile' : '.profile'
          I18n.t(t_key)
          end


          and on the view



          %strong= some_name_for_the_method(@enterprise)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 31 at 19:40









          arieljuodarieljuod

          8,15711222




          8,15711222












          • Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

            – Syed Usama Amer
            Apr 1 at 20:18

















          • Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

            – Syed Usama Amer
            Apr 1 at 20:18
















          Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

          – Syed Usama Amer
          Apr 1 at 20:18





          Thank you so much. I ended up coming up with your first suggestion but I was wondering about how to make the alternate approaches you have mentioned. I appreciate the help and lesson!

          – Syed Usama Amer
          Apr 1 at 20:18



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55305674%2fcorrect-format-for-writing-conditionals-in-ruby-and-then-converting-output-into%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript