Kubernetes If/Or Statement in Configmap - if-statement

Im trying to write an IF statement in my configmap but I cannot find any sites that combine and IF statement with OR. For example:
<% if #project_name == 'site-a' || 'site-b' %>
security:
default-groups:
- reader # Read only for everybody
<% end %>
Would this be accurate? Ideally, if the variable is called site a or site b. I can probably do an else block but it's not necessary.
Thanks.

The initial code was not using the comparison correctly.
In the first line you only evaluated the the project in the first part and assumed that computer will know that the same operation is applied to both values.
<% if #project_name == 'site-a' || 'site-b' %>
The operator doesn't checks if a value is a member of a set which means you should check each #project_name explicitly so that both values are compared:
<% if #project_name == 'site-a' || #project_name == 'site-b' %>

Related

Dancer2 IF statements in template

I'm working on a page that has a dropdown menu that gets populated from a database query. I also have an incoming parameter that, if it's populated, will match one of the options in the dropdown. If that parameter is populated, I want the option in the drowpdown to be selected. My instinct is to do something like the following (where foo is an entry in a FOREACH):
<% IF param -eq foo %>
<option value="foo" selected="selected">foo</option>
<% ELSE %>
<option value="foo">foo</option>
<% END %>
The problem is that I get an error that foo is an unrecognized token.
I can't find any evidence in documentation or examples that I can actually use the param -eq foo construct above. The examples I can find of IF statements don't use comparative operators. They basically only read a boolean parameter or check that a parameter has a value. But since it doesn't reject the -eq token, I've been holding out hope that there's a way to do it and that I just haven't figured out the right syntax or found the documentation yet.
Found the pertinent documentation: http://template-toolkit.org/docs/manual/Directives.html#section_IF_UNLESS_ELSIF_ELSE
It's not -eq, it's ==. But that being the case, I'm still not sure why -eq didn't throw an error.

Rails, filterrific with multiple parameters

I'm using the most recent ruby + rails, with the filterrific gem. It works great - but how can multiple parameters per scope be used? For single column filtering it is simple, but for the following scenario, how would it be handled?
Filter by X miles of zipcode Y
Scopes currently only have knowledge of the value being modified (EITHER miles, OR zipcode - two different scopes), but neither have knowledge of the other. This filter scenario requires knowledge of miles and zipcode. I have searched the documentation thoroughly and see no way. Has anyone done this before or am I missing something hidden in the documentation?
You can use Rails' fields_for form helper to submit a hash with multiple keys and values to a single filterrific enabled scope:
<%= f.fields_for :with_distance do |with_distance_fields| %>
<%= with_distance_fields.text_field :max_distance %>
<%= with_distance_fields.text_field :city %>
<% end %>
Then you can access the various values in the scope like so:
scope :with_distance, lambda { |distance_attrs|
# `distance_attrs` is a hash with two keys:
# {
# :max_distance => '10',
# :city => 'Vancouver',
# }
where(...)
}
This is tested with Filterrific 1.4.2 and Rails 4.1

Need help passing dynamic list of files to partial. Can't get list to pass successfully in Rails

In my application/index, the user selects a location and directory path from a drop down list. onchange event makes a call to the controller called file_dir where it takes the path, executes a command line call passing back a list of files in that directory to a parameter #files. I then render a partial passing this #files to a local variable. Then in the partial the select tag will display with the list of file passed to it.
I am new to ROR and have not been able to successfully pass a readable local variable. to the partial. Everything works fine with a hardcoded line but not with the local variable.
Can someone please help advise me on the correct way to set this up?
Here is the method called from the first onchange dropdown pass that receives the directory:
def file_dir
unless params[:dir_list].nil?
#dir_path_choice = params[:dir_list]
else
#dir_path_choice = '/watchfolder/indemandvod'
end
# #files = "#{#dir}"
#files = Dir.glob("#{#dir_path_choice}/**/*.{mpg,mov}").map
if #files.nil?
#files = Dir.glob("/watchfolder/hbovod/**/*.{mpg,mov}").map
end
render :partial => 'list_files', :locals => { #list => #files }
end
In irb I tested the #files = Dir.glob("#{#dir_path_choice}/**/*.{mpg,mov}").map line to make sure this was processing correctly. Here is what #files looks like:
1.9.3-p547 :008 > #files
=> #<Enumerator: ["/watchfolder/indemandvod/MJR-TEST.mov", "/watchfolder/indemandvod/MJR-TEST-AWS1.mov", "/watchfolder/indemandvod/MJR-TEST-AWS.mov", "/watchfolder/indemandvod/MJR-TEST2.mov", "/watchfolder/indemandvod/PIX_Gor_SVO40185/PIX_Gor_SVO40185_mezz.mov"]:map>
This data breaks out in the select list, separated by the commas.
NOTE: I did try to pass the #list without the # symbol but I got unidentified local variable or method and couldn't get the code to run with out adding the #. This is like a collection of data so I expect it is interpreting it as an array. Not sure though.
Here is the partial file code:
<p>
<label>Select Partial Test File List:</label><%= #list %><br />
<% unless #list.nil? %>
<%= #list %>
<% else %>
<label> list is empty. </label>
<% #list = Dir.glob("/watchfolder/showtimevod/**/*.{mpg,mov}").map %>
<% end %>
<%= select_tag 'filepath', options_for_select(#list, #selected_filepath) %>
</p>
It does display back on the page and my 'list is empty' always shows and the dropdown box populates with my default 'hardcoded' command line for '/watchfolder/showtimevod/' files list.
The #selected_filepath maintains the selected line in the list.
I don't know what I am doing wrong in passing values to partials.
In my application/index,
What is an "application/index"?
Can someone please help advise me on the correct way to set this up?
The correct way is to get something simple to work first:
app/controllers/some_controller.rb
def file_dir
puts "****#{params[:dir_list]}"
#files = %w[ a b c]
render :partial => 'list_files', :locals => { file_names => #files }
end
views/some_controller/_list_files.htm.erb:
<div>
<%= file_names.each do |fname| %>
<div><%= fname %></div>
<% end %>
</div>
And as with all your posts, in this line:
<%= select_tag(
'filepath',
options_for_select(#list, #selected_filepath) %>
#selected_filepath is undefined.
This is like a collection of data so I expect it is interpreting it as
an array. Not sure though.
You should probably strive to create data that you understand. What are you trying to accomplish with this line:
#files = Dir.glob("#{#dir_path_choice}/**/*.{mpg,mov}").map
that the following line doesn't do:
#files = Dir.glob("#{#dir_path_choice}/**/*.{mpg,mov}")
This:
I did try to pass the #list without the # symbol but I got
unidentified local variable or method and couldn't get the code to run
with out adding the #.
is not sufficient. No one cares what your interpretation of the error message is--what people care about is the EXACT error message, with file names and line numbers, copy and pasted into your post, along with the exact code the error refers to.
If you just want to get your code to work, you can do this:
app/some_controller.rb:
def file_dir
if params[:dir_list].nil?
#dir_path_choice = '/watchfolder/indemandvod'
else
#dir_path_choice = params[:dir_list]
end
#files = Dir.glob("#{#dir_path_choice}/**/*.{mpg,mov}").map
if #files.nil?
#files = Dir.glob("/watchfolder/hbovod/**/*.{mpg,mov}").map
end
render :partial => 'list_files', :locals => {file_names => #files }
end
However, adding map() to the end of your Dir.glob() does nothing useful.
app/views/some_controller/_list_files.html.erb:
<p>
<label>Select Partial Test File List:</label>
<%= select_tag 'filepath', options_for_select(file_names) %>
</p>

Addling Line Break in Vim with Substitution

There is a really helpful article on Vim's wiki here that is nearly exactly what I want to do, I think I'm just missing something small.
I would like to take this line:
<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
and make it into:
<%= simple_form_for(resource,
as: resource_name,
url: session_path(resource_name)
) do |f| %>
However when I run:
/[(,)]
:s//\r&/g
I get:
<%= simple_form_for
(resource
, as: resource_name
, url: session_path
(resource_name
)
) do |f| %>
I need the linebreaks to happen AFTER the commmas and I'm unsure the regex to provide to make that happen. Thoughts?
Here is how you would replace every comma by a comma followed by a newline.
:s/,/&\r/g
If you also want to separate every pair of two )) by a newline, you can do this.
%s/))/)\r)/g
Thanks #FDinoff ! I figured it out, it was simply rearranging my search & replace with:
:s//&\r/g

Why is this erb code throwing "Undefined method 'match' for []:Array"?

Hope someone can help me resolve this problem.
I have an instance variable holding some string values in a params. Here are the string values:
"The Hoboken Four" "Anita Baker" "No One Cares" "Giant" "Taking A Chance On Love" "[]" "["quiz"]" "quiz"
I would like to display only the values that match:
"The Hoboken Four" "Anita Baker" "No One Cares" "Giant" "Taking A Chance On Love"
Here is the code in my app.rb:
post '/:form_type' do
#array = []
#results = params
#results.each do |key, value|
if value.match(/\w[^["quiz"]]/)
#array << value
end
#array
end
erb :results
end
Here is the code I have in my view:
<% #array.each do |item| %>
<p><%= item %></p>
<% end %>
Thank you for helping!
Just for the record, what I think happened is that OP was using [] in the parameters name, most likely to send all the values under a unique name. For instance if the HTML form looks like that:
<input type="text" name="title[]"/>
<input type="text" name="title[]"/>
and the user inputs First and Second, Sinatra is going to interpret the [] in the parameter name and aggregate the different values in a table:
{"title"=>["First", "Second"]}
So in OP's code, value.match was throwing because value was of type Array (as the error message states).