Conditionally adding class - asp.net-mvc

<span class=#Model.TotalSent<0?"small":"big">show me only if #Model.TotalSent >0 </span>
The above line is a code that I expect class="big" will be rendered if #Model.TotalSent>0
else class="small" will be rendered.
But is not happening
What is the real syntax to do this?

Try this:
<span class='#(Model.TotalSent < 0 ? "small" : "big")'>show me only if #Model.TotalSent >0 </span>

Try surrounding your expression in parentheses, and make sure you put quotes around your class.
<span class='#( Model.TotalSent < 0 ? "small" : "big" )'>...

class="#(Model.TotalSent < 0 ? "small":"big")"

Related

attempt to index a nil value on FiveM esx_policejob

attempt to index a nil value (local 'weapon')
In the first line is the error
local component = weapon.components[i]
local hasComponent = HasPedGotWeaponComponent(playerPed, GetHashKey(v.weapon), component.hash)
if hasComponent then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_owned'))
else
if v.components[i] > 0 then
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_item', ESX.Math.GroupDigits(v.components[i])))
else
label = ('%s: <span style="color:green;">%s</span>'):format(component.label, _U('armory_free'))
end
end
I am not completely sure if this works out, but that would be my solution:
Check if you have this in your script!
ESX=nil
if not write it at the top!

How to scrape a span name in Nokogiri in Ruby?

I want to scrape data off a website. The data is in the text of a span.
The HTML looks like this:
<p class="text-muted text-small">
<span class="text-muted">Votes:</span>
<span name="nv" data-value="1564808">1,564,808</span>
<span class="ghost">|</span>
<span class="text-muted">Gross:</span>
<span name="nv" data-value="107,928,762">$107.93M</span>
</p>
I want to search the whole page and get the value of the data-value which is 1,564,808 not the 107.93M value.
I tried various ways to get the data, Like for instance:
#votes = []
html_content =
open("https://www.imdb.com/list/ls057823854/sort=list_order,asc&st_
dt=&mod e=detail&page=1").read
doc = Nokogiri::HTML(html_content)
doc.css(".text-muted['span name=nv']").each do |i|
#votes << i.text.strip
Try this code:
doc.css('div.lister-item-content > p.text-muted > span[name = nv]:nth-child(2)').map(&:text)
Which results in:
["1,564,941", "373,745", "2,004,624", "1,077,404", "887,189", "305,554", "207,904", "1,074,609", "748,393", "789,255", "1,224,753", "754,008", "634,752", "1,056,328", "1,604,158", "1,438,194", "629,504", "1,158,452", "517,609", "539,263", "1,443,979", "1,290,159", "161,981", "830,992", "1,427,193", "299,532", "289,184", "705,138", "615,264", "1,147,650", "1,030,826", "1,018,932", "921,730", "524,568", "557,482", "1,973,773", "813,743", "367,587", "342,800", "188,210", "649,467", "1,068,455", "547,990", "527,123", "805,964", "420,447", "441,780", "318,295", "1,004,742", "446,096", "203,977", "581,108", "1,754,019", "616,804", "484,534", "265,048", "958,244", "289,190", "651,605", "503,185", "320,564", "660,685", "476,016", "432,155", "588,572", "374,705", "378,561", "337,801", "463,467", "508,822", "187,810", "1,128,184", "221,361", "261,529", "322,314", "324,435", "116,258", "318,628", "1,334,595", "222,651", "1,155,754", "228,713", "205,956", "271,162", "293,774", "33,136", "80,385", "703,048", "195,712", "274,244", "233,133", "121,874", "208,462", "513,797", "485,112", "120,750", "135,232", "57,411", "125,431", "297,193"]

ng-options for ActiveSupport::TimeZone returns Unexpected end of expression: [

I'm trying to list timezone options in an erb file. I have the following code to do so:
<select class="pull-left" ng-model="schedule.deliver_timezone"
ng-options="zone for zone in <%= ActiveSupport::TimeZone.zones_map.map { |zone_name, zone_desc| zone_name.to_s } %>"
name="deliver_at_tz"/>
If I just run ActiveSupport::TimeZone.zones_map.map { |zone_name, zone_desc| zone_name.to_s }, I get an array of timezone names as expected. However, when actually hitting this template, I get:
Unexpected end of expression: [
This dumps out the following mess into the console:
<select class="pull-left ng-pristine ng-valid" ng-model="schedule.deliver_timezone" ng-options="zone for zone in [" utc",="" "eastern="" time="" (us="" &="" canada)",="" "international="" date="" line="" west",="" "midway="" island",="" "american="" samoa",="" "hawaii",="" "alaska",="" "pacific="" "tijuana",="" "mountain="" "arizona",="" "chihuahua",="" "mazatlan",="" "central="" "saskatchewan",="" "guadalajara",="" "mexico="" city",="" "monterrey",="" america",="" "indiana="" (east)",="" "bogota",="" "lima",="" "quito",="" "atlantic="" (canada)",="" "caracas",="" "la="" paz",="" "santiago",="" "newfoundland",="" "brasilia",="" "buenos="" aires",="" "georgetown",="" "greenland",="" "mid-atlantic",="" "azores",="" "cape="" verde="" is.",="" "dublin",="" "edinburgh",="" "lisbon",="" "london",="" "casablanca",="" "monrovia",="" "belgrade",="" "bratislava",="" "budapest",="" "ljubljana",="" "prague",="" "sarajevo",="" "skopje",="" "warsaw",="" "zagreb",="" "brussels",="" "copenhagen",="" "madrid",="" "paris",="" "amsterdam",="" "berlin",="" "bern",="" "rome",="" "stockholm",="" "vienna",="" "west="" central="" africa",="" "bucharest",="" "cairo",="" "helsinki",="" "kyiv",="" "riga",="" "sofia",="" "tallinn",="" "vilnius",="" "athens",="" "istanbul",="" "minsk",="" "jerusalem",="" "harare",="" "pretoria",="" "moscow",="" "st.="" petersburg",="" "volgograd",="" "kuwait",="" "riyadh",="" "nairobi",="" "baghdad",="" "tehran",="" "abu="" dhabi",="" "muscat",="" "baku",="" "tbilisi",="" "yerevan",="" "kabul",="" "ekaterinburg",="" "islamabad",="" "karachi",="" "tashkent",="" "chennai",="" "kolkata",="" "mumbai",="" "new="" delhi",="" "kathmandu",="" "astana",="" "dhaka",="" "sri="" jayawardenepura",="" "almaty",="" "novosibirsk",="" "rangoon",="" "bangkok",="" "hanoi",="" "jakarta",="" "krasnoyarsk",="" "beijing",="" "chongqing",="" "hong="" kong",="" "urumqi",="" "kuala="" lumpur",="" "singapore",="" "taipei",="" "perth",="" "irkutsk",="" "ulaan="" bataar",="" "seoul",="" "osaka",="" "sapporo",="" "tokyo",="" "yakutsk",="" "darwin",="" "adelaide",="" "canberra",="" "melbourne",="" "sydney",="" "brisbane",="" "hobart",="" "vladivostok",="" "guam",="" "port="" moresby",="" "magadan",="" "solomon="" caledonia",="" "fiji",="" "kamchatka",="" "marshall="" "auckland",="" "wellington",="" "nuku'alofa",="" "tokelau="" "samoa"]"="" name="deliver_at_tz">
I'm not really sure exactly how this format is supposed to look, but it's clearly wrong. What exactly is wrong with this logic?
Full trace (santizied for sensitive info):
Error: [$parse:ueoe] Unexpected end of expression: [
http://errors.angularjs.org/1.3.0-beta.10/$parse/ueoe?p0=%5B
at http://127.0.0.1:3000/application.js <select class="pull-left ng-pristine ng-valid" ng-model="schedule.deliver_timezone" ng-options="zone for zone in [" utc",="" "eastern="" time="" (us="" &="" canada)",="" "international="" date="" line="" west",="" "midway="" island",="" "american="" samoa",="" "hawaii",="" "alaska",="" "pacific="" "tijuana",="" "mountain="" "arizona",="" "chihuahua",="" "mazatlan",="" "central="" "saskatchewan",="" "guadalajara",="" "mexico="" city",="" "monterrey",="" america",="" "indiana="" (east)",="" "bogota",="" "lima",="" "quito",="" "atlantic="" (canada)",="" "caracas",="" "la="" paz",="" "santiago",="" "newfoundland",="" "brasilia",="" "buenos="" aires",="" "georgetown",="" "greenland",="" "mid-atlantic",="" "azores",="" "cape="" verde="" is.",="" "dublin",="" "edinburgh",="" "lisbon",="" "london",="" "casablanca",="" "monrovia",="" "belgrade",="" "bratislava",="" "budapest",="" "ljubljana",="" "prague",="" "sarajevo",="" "skopje",="" "warsaw",="" "zagreb",="" "brussels",="" "copenhagen",="" "madrid",="" "paris",="" "amsterdam",="" "berlin",="" "bern",="" "rome",="" "stockholm",="" "vienna",="" "west="" central="" africa",="" "bucharest",="" "cairo",="" "helsinki",="" "kyiv",="" "riga",="" "sofia",="" "tallinn",="" "vilnius",="" "athens",="" "istanbul",="" "minsk",="" "jerusalem",="" "harare",="" "pretoria",="" "moscow",="" "st.="" petersburg",="" "volgograd",="" "kuwait",="" "riyadh",="" "nairobi",="" "baghdad",="" "tehran",="" "abu="" dhabi",="" "muscat",="" "baku",="" "tbilisi",="" "yerevan",="" "kabul",="" "ekaterinburg",="" "islamabad",="" "karachi",="" "tashkent",="" "chennai",="" "kolkata",="" "mumbai",="" "new="" delhi",="" "kathmandu",="" "astana",="" "dhaka",="" "sri="" jayawardenepura",="" "almaty",="" "novosibirsk",="" "rangoon",="" "bangkok",="" "hanoi",="" "jakarta",="" "krasnoyarsk",="" "beijing",="" "chongqing",="" "hong="" kong",="" "urumqi",="" "kuala="" lumpur",="" "singapore",="" "taipei",="" "perth",="" "irkutsk",="" "ulaan="" bataar",="" "seoul",="" "osaka",="" "sapporo",="" "tokyo",="" "yakutsk",="" "darwin",="" "adelaide",="" "canberra",="" "melbourne",="" "sydney",="" "brisbane",="" "hobart",="" "vladivostok",="" "guam",="" "port="" moresby",="" "magadan",="" "solomon="" caledonia",="" "fiji",="" "kamchatka",="" "marshall="" "auckland",="" "wellington",="" "nuku'alofa",="" "tokelau="" "samoa"]"="" name="deliver_at_tz">
Try doing this, should work
<select class="pull-left"
ng-model="schedule.deliver_timezone"
ng-options='zone for zone in <%= "[\"#{ActiveSupport::TimeZone.zones_map.values.collect{|z| z.name }.join('","')}\"]" %>'
name="deliver_at_tz" />

Display in view for a specific value

I m working on app and i have a question for you. I m trying to display field for a specific value. I have 2 value "oui" and "non". I m done an if condition but doesn't work, value "non" is always display. I don't want to display this.
My value in db
Plage = oui
Etang = oui
Montagne = oui
Riviere = non
<% #camping.situations.each do |situation| %>
<% if situation.plage == "oui" || situation.etang == "oui" || situation.montagne == "oui" || situation.riviere == "oui" %>
<p> Plage: <%=situation.plage %> à <%=situation.distanceplage%> km</p>
<p> Etang: <%=situation.etang%></p>
<p> Montagne: <%=situation.montagne %></p>
<p> Rivière: <%=situation.riviere%></p>
<% else %>
<%end%>
<%end%>
Can you help me ?
Your 'if' check will evaluate to TRUE when any of you variables are equivalent to "oui".
In your exmple, Plage is == "oui". This means that your IF check will ignore the next checks for the other variables because you are using OR checks. This is called Short Circuiting (https://en.m.wikipedia.org/wiki/Short-circuit_evaluation) in programming.
Consider using an "&&" statement instead of "||". That way when any one of us your variables is "non", it won't display that view.

elsif statements not working in views

I need help understanding the usage of elseif statements in the view for Rails. I have done it before but now I am doing it with SLIM and I can't seem to get it to work. I want it to print out the word "him" or "her" depending on the current user gender. The code I am using is printing out the elsif statement in text.
a.profile_btn href="#" data-mfp-src='#ask_me'
img alt="" src="/assets/login_icon2.png" /
if current_user.gender == "male"
span Ask Him Out
elsif current_user.gender == "female"
span Ask Her Out
The original code:
a.profile_btn href="#" data-mfp-src='#ask_me'
img alt="" src="/assets/login_icon2.png" /
span Ask This User Out
Try
- if current_user.gender == "male"
span Ask Him Out
- elsif current_user.gender == "female"
span Ask Her Out

Resources