Displaying 20 results from an estimated 300 matches similar to: "STI with_scope on parent - bug or feature?"
2017 Nov 06
0
For each entry type in column?
Hello,
If you want to loop through the columns of a data.frame you can do
for(i in names(df)){
[code]
}
Another way would be
lapply(names(df), function(somecol) class(df[[somecol]]))
where class(df[[somecol]]) is just an example, you would use whatever
fits your needs.
When you say that the column in question holds "levels" do you mean it's
a factor? (factors are R's
2017 Nov 06
2
For each entry type in column?
Matti -
Since you are asking about looping through a column, not looping across columns, it is simply the following:
# Note: data.frame() turns strings into factors by default.
myDF <- data.frame(type = c("a", "j", "a", "a", "j"),
weight = c(12.3, 6.8, 10.5, NA, "5.5"))
myDF$type # ... is a vector of factors
2017 Nov 06
0
For each entry type in column?
Boris:
"As others have remarked, for added efficiency with large datasets we often
use functions from the apply() family, rather than for-loops."
That is generally false, though it is a common misconception. Apply-type
functions are used to maintain fidelity -- and for some, clarity -- to a
functional programming paradigm.
Cheers,
Bert
Bert Gunter
"The trouble with having an
2017 Nov 06
4
For each entry type in column?
It?s sometimes faster to ask from someone who has already learnt the syntax.
In this case one has to do e.g.
names(data$somecol)
To get the collection and then iteration through it is almost like in Python:
for(i in names(data$somecol)) {
# do something
}
> Bert Gunter <bgunter.4567 at gmail.com> kirjoitti 6.11.2017 kello 19.55:
>
> Time to go through a tutorial or two! --
2006 Nov 01
17
So how can I rewrite my app without using with_scope?
So, I hear that with_scope is going to be deprecated.
Which is a bit of a shame, given the stuff I''ve been writing recently.
I have a CMS with multiple clients. A ''client'' is essentially a
company, with multiple users. Content on the site belongs to a client
- content could be messages, images, schedules, etc etc. People
belonging to one client should not be able
2010 Jan 27
1
around_filter and with_scope
i got two controller (with restful actions) where my code is quite
ugly and not very dry. every action looks quite like this:
if @logged_user.has_role?("admin")
User.find(params[:id)
else
@logged_user.group.user.find(params[:id])
this is a security check that enforce a simple spec: normal user
should read/write information only about their group''s users, but
2006 Jul 23
0
[PATCH] (+tests) with_scope :order doesn''t work with included associations
(I''ve had this patch lying around for a couple of weeks, waiting for
Trac to come back up. noradio''s already had a look at it on IRC.
What''s the best way to submit patches while Trac is down?)
with_scope doesn''t support :order in the presence of :include. For
example:
{{{
# We''re testing the interaction between :order, :include, and
2006 Apr 03
0
with_scope used in a has_many :through model
Hi there,
I have something like the following:
class Person < AR:B
...
...
has_many :votes
has_many :chosen_answers, :through => :votes, :source => :answer, :select => ''DISTINCT answers.*'' do
def my_answers(whodunnit)
chosen_answers.with_scope(:find => { :conditions => [ "votes.created_by=?", whodunnit ] }) do
chosen_answers.find :all
2006 Mar 02
0
EdgeRails with_scope and :select
>From what i can gather the with_scope feature doesn''t allow you to
specify which columns get selected. It appears to default to "*". So
if i specify something like:
Question.with_scope( :find => {
:from => "questions q, answers a",
:conditions => "q.owner = a.owner AND a.owner=1"
}) do
...
end
I''ll generate SQL like:
SELECT *
2006 Mar 30
4
with_scope and filters for Rails 1.1 (scoped_access plugin)
Has anyone successfully gotten the scoped_access[1] plugin to work in
Rails 1.1? Some of the methods it was relying on are now no longer
accessible. It seems the only way to add scope is to use the
''with_scope'' method that takes a block, but since Rails doesn''t have
real around filters[2] I cannot see a way of adding a scope using a
filter.
Anyone using with_scope
2006 Jul 23
4
Anything like with_scope for ActionController?
There are areas of my application that "want" to use a url structure
like
domain/<human_readable_param>/<Module>/<Controller>/<Action>/<Id>
Please note that the human readable parameter I need to inject is NOT
related to the <id> being used by the action/controller pair. It''s
identifying a container object whose contains are operated
2007 Oct 18
9
with_scope issue
I have the following code:
class User < ActiveRecord::Base
has_many :requests do
def find_active(options = {})
with_scope :find => { :conditions => ["requests.active = ?",
true] } do
find(:all, options)
end
end
end
end
Executing user.requests.find_active results in the following SQL:
SELECT * FROM requests WHERE (( requests.user_id = 10 ) AND
(
2006 Jun 26
0
with_scope with new
Why does with_scope work with .create, .find, but not with .new? It
breaks all scaffolded code :(
--
Posted via http://www.ruby-forum.com/.
2006 Sep 08
1
has_many relationship extensions and scoping rules
Hi all !
Is this supposed to work ?
class Email < ActiveRecord::Base
has_many :to, :class_name => 'Recipient', :conditions =>
"recipients.source = 'to'" do
def create!(*args)
with_scope(:create => {:source => 'to'}) do
super
end
end
def build(*args)
with_scope(:create => {:source => 'to'}) do
2006 Nov 21
2
Accessing scopes
If with_scope has been called previously, how do I access the find
conditions dynamically?
I am asking because I am using a find_by_sql call (which clobbers the
with_scope). How can I access the method scoping so that I can read it
and incorporate it into my query manually?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
2006 Jul 02
11
Rails Plugin: meantime_filter for controllers (actions within blocks)
Hello, I just finished writing a plugin for Rails that I''m annoucing
the first release here: meantime_filter.
It is descibed at http://roman2k.free.fr/rails/meantime_filter/0.1.0/
rdoc/
(See the end of this message for getting it.)
ABOUT THE PLUGIN
It extends ActionController to add the functionnality of having
filters run at the action call time. This new type of filter yields
2017 Nov 06
0
For each entry type in column?
Time to go through a tutorial or two! -- This forum cannot replace such
self study.
Your query evidences some basic confusion, but ?tapply or the equivalent
lapply(split(...)) construct are most likely relevant.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his
2010 Oct 14
1
Cucumber Selenium web step to verify value of input field
I have an input field with an id which has a value. The web_steps.rb method
does not find the value. Is this the right step to use to check an input
field? It works fine for a text_area but not an input.
Scenario steps (tried both ways):
Then the "travel_card_number_gate" field should contain "5"
Then the "#travel_card_number_gate" field should contain "5"
2001 Nov 27
2
accessing information in data.frame
After reading a data.frame using, such as a <- read.spss("data.sav")
I want to give the column index 'i', or a[i] to a function, which after
some calculation, should print out the results to the standard output.
I am struggling how to access the data itself, as e.g. sum(a[i]) does
not work in this context. In addition I need to know the name of the
variable within the
2006 Jun 26
0
How to limit access to model objects based on role?
Hi all,
I want to limit access to model objects based on the role of the logged in
user. It seemed the most blunt way of doing this would be make copies of
each controller which accessed the models and use one of the access control
systems out there to limit access to the controllers. However, with 9
different controllers this seems like a terrible choice.
Here''s what I''ve