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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현