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;
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
add a comment |
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
add a comment |
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
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
ruby-on-rails-3 if-statement haml string-interpolation
edited Mar 22 at 19:15
Syed Usama Amer
asked Mar 22 at 18:19
Syed Usama AmerSyed Usama Amer
33
33
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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)
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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