Sorry if this is a simple problem that has been explained before. I've done some research about my problem. I'm completely new to ruby and active record and I find the examples other have had with the wrong number of arguments too complicated for me to follow. So here is my simple one.
I'm trying to do a simple update using activerecord to a db. All I'm trying to do add a value to the title attribute that I left as nil when I created it in the first place.
vertigo is the variable I assigned using the .find method.
I'm typing in vertigo.update(title: 'Vertigo')
But I'm getting an error message saying
wrong number of arguments (1 for 2).
Here is more of session. I'm using Sinatra-tux >> vertigo = Movie.all
D, [2015-04-20T11:11:38.890714 #3741] DEBUG -- : Movie Load (0.4ms) SELECT "movies".* FROM "movies"
=> #]>
vertigo.update title: "Vertigo"
ArgumentError: wrong number of arguments (1 for 2)
/home/michael/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/activerecord-4.0.4/lib/active_record/relation.rb:330:in update'
(ripl):4:in'
find can return an array. It's entirely possible that your vertigo variable is actually an array.
Try to run
vertigo[0].update(title: 'Vertigo')
assuming you only want to change the first one.
Related
When I run my code one error occurs with my code setindex! not defined for WeakRefStrings.StringArray{String,1}
CSV File here.
using CSV
EVDdata =CSV.read(raw"wikipediaEVDdatesconverted.csv")
EVDdata[end-9:end,:]
And the Error Code is here
rows, cols = size(EVDdata)
for j =1:cols
for i = 1:rows
if !isdigit(string(EVDdata[i, j])[1])
EVDdata[i,j] = 0
end
end
end
I am working with Julia 1.4.1 on Jupter Notebook
setindex!(collection, item, inds...) is the function that colection[inds...] = item gets lowered to. The error comes from the fact that CSV.read makes an immutable collection.
As Oscar says in his answer, setindex! tries to mutate its arguments, i.e. change the contents of your column in place. When you do CSV.read(), by default immutable columns of type CSV.Column are returned. This is done for performance reason, as it means columns don't have to be copied after parsing.
To get around this, you can do two things:
Pass the keyword argument CSV.read(raw"wikipediaEVDdatesconverted.csv", copycols = true) - this will copy the columns and therefore make them mutable; or
Achieve the same by using DataFrame((raw"wikipediaEVDdatesconverted.csv"))
The second way is the preferred way as CSV.read will be deprecated in the CSV.jl package.
You can see that it's current implementation is basically doing the same thing I listed in (2) above in the source here. Removing this method will allow CSV.jl not to depend on DataFrames.jl anymore.
It could also be done this way
col1dt = Vector{Dates.DateTime}(undef, length(col1))
for v = 1:length(col1)
col1dt[v] = Dates.DateTime(col1[v], "d-u-y")
end
I have a question concerning the use of presentation variables:
1) What's the correct syntax for filtering on a presentation variable is used? You allow a user to select multiple values in a filter eg. A and B. If you use the syntax = '#{PV}{%}' it will result in this sql: = 'A, B' which of course won't exist in the data. I'd like to have this result: in ('A', 'B').
I've already found this syntax: (#{PV}['#']) which gives the correct sql, only thing here is that this doesn't work when you have a dashboard prompt where you allow 'all column values'. When no value is passed to this presentation variable, the analysis throws an error. I have no idea how to put a default value in this one. Any ideas on this?
2) Is there any configuration or setting where you can push obi to use a presentation variable in stead of using the 'normal' way of filtering as shown here:
The obi way is that it changes the relation to the relation in the prompt (if the prompt says 'is greater than' it will change here as well, even though you've put here 'is equal to'), but it will also use a value for this dimension if there's ever been a value for this, rather than listening to the value in the presentation variable of the dashboard prompt. I know that you can translate this to SQL but that's not the way to go for me. The behaviour I'd like is (in this exact order):
- when there is a value in the presentation variable in the dashboard prompt, take this.
- when there is a value for this role of the dimension, take that.
The reason why is because we have this dimension 'Afdeling' which can take up many roles but our customer asked for the roles to be hidden from the end user. This means that even though you switch roles, the end user always sees 'Afdeling' and couldn't care less in which role it is looking at its 'Afdeling'. They can switch between different dashboard pages and if I'd put on top of the page the dashboardprompt of the 'Afdeling' in the role it needed to be, the value won't pass through when switching pages to another dashboardprompt of another role. That way the end user would know something was up. So the value needs to pass through the prompt on each page, no matter what the role of that dimension.
After a bit of googling I've found the answer to question 1 myself. Thanks to this website https://www.obieetips.com/2014/05/obiee-11g-using-multiple-value-for.html I now know that the correct syntax is (#{pv_region}['#']{'West '})
I'ts my first tme using Cypress and I almost finalized my first test. But to do so I need to assert against a unknown number. Let me explain:
When the test starts, a random number of elements is generated and I shouldn't have control on such a number (is a requirement). So, I'm trying to get such number in this way:
var previousElems = cy.get('.list-group-item').its('length');
I'm not really sure if I'm getting the right data, since I can not log it (the "cypress console" shows me "[Object]" when I print it). But let's say such line returns (5) to exemplify.
During the test, I simulate a user creating extra elements (2) and removing an (1) element. Let's say the user just creates one single extra element.
So, at the end os the test, I need to check if the number of eements with the same class are equals to (5+2-1) = (6) elements. I'm doing it in this way:
cy.get('.list-group-item').its('length').should('eq', (previousTasks + 1));
But I get the following message:
CypressError: Timed out retrying: expected 10 to equal '[object Object]1'
So, how can I log and assert this?
Thanks in advance,
PD: I also tryed:
var previousTasks = (Cypress.$("ul").children)? Cypress.$("ul").children.length : 0;
But it always returns a fixed number (2), even if I put a wait before to make sure all the items are fully loaded.
I also tryed the same with childNodes but it always return 0.
Your problem stems from the fact that Cypress test code is run all at once before the test starts. Commands are queued to be run later, and so storing variables as in your example will not work. This is why you keep getting objects instead of numbers; the object you're getting is called a chainer, and is used to allow you to chain commands off other commands, like so: cy.get('#someSelector').should('...');
Cypress has a way to get around this though; if you need to operate on some data directly, you can provide a lambda function using .then() that will be run in order with the rest of your commands. Here's a basic example that should work in your scenario:
cy.get('.list-group-item').its('length').then(previousCount => {
// Add two elements and remove one...
cy.get('.list-group-item').its('.length').should('eq', previousCount + 1);
});
If you haven't already, I strongly suggest reading the fantastic introduction to Cypress in the docs. This page on variables and aliases should also be useful in this case.
I have been struggling to return the count of courses from this XML file that contain "Cross-listed" as their description. The problem I encounter is because I am using for, it iterates and gives me "1 1" instead of "2". When I try using let instead I get 13 which means it counts all without condition even when I point return count($c["Cross-listed"]. What am I doing wrong and how can I fix it? Thanks in advance
for $c in doc("courses.xml")//Department/Course
where some $desc in $c/Description
satisfies contains($desc, "Cross-listed")
return count($c)
The problem I encounter is because I am using for
You are quite correct. You don't need to process items individually in order to count them.
You've made things much too difficult. You want
count(doc("courses.xml")//Department/Course[Description[contains(., "Cross-listed"]])
The key thing here is: you want a count, so call the count() function, and give it an argument which selects the set of things you want to include in the count.
I am testing a registration form and one of the questions before submitting is:
"What is 8 + 4?"
The values will be different every time. I am using Selenium 2 with Ruby and want to to see if anyone knows how to a) get the text from the question and then b) compute the addition and return the correct answer in the field.
Thanks!
Using ruby code try to get the values in between is and ? Store this in Variable and now split the text with deliminator + now you will get the Values in array in different location. Now you can add these two and use for your evaluation. I don't have idea about ruby but its possible in PHP as I have done the same. Its should be in Ruby too.
Getting text between is and ? can be done strpos() in php that gives the position of the string see similar function for ruby.