Displaying 20 results from an estimated 2000 matches similar to: "looking for more idiomatic way of doing this"
2006 Jul 14
3
compare two tables and find the difference?
I need to compare a column in TableA to a column in TableB and then
select 3 columns from TableA for all the records in TableA that don''t
exist in TableB.
TableA and TableB are different but do have one field in common that i
am comparing. The tables are not related in anyway.
right now I have a find_by_sql query located in a model that looks like
this:
def self.absent_charges
2006 Apr 10
4
Best way to propogate model rules to controller?
Hey everybody,
I''ve got a model that represents kind of a turn-based games. Certain
actions can only be made unders certain conditions. For simplicity,
we''ll say that the only condition for a particular action is that the
weekday be Tuesday.
def add_vote
raise ''You cannot vote today'' unless Date.today.wday == 2
...
end
In my controller I want to show a
2006 Jul 17
0
collection_select help
I can''t figure out how to get the collection_select to correctly
identify and select the appropriate option in the drop down to begin
with. i have checked that charge.offense_level contains the correct
value to begin with (a number between 1 and 10) but the view still
defaults to the first option and not the one contained in the
charge.offense_level. what am i doing wrong? any
2006 May 27
0
newbie question: creating views to submit values
Apologies for such a basic question. I''ve wracked my brain on this a
couple days so if anyone takes pity, please help me out.
I''ve been looking at STI (Single Table Inheritance) at the Rails Wiki
and decided to try it out. I got it working in the model and
controllers but can''t figure out how to make a proper view that will
take the values and add them into the
2006 Jun 27
0
More idiomatic way of doing this
Folks,
I''m trying to write a validating filter that checks if the user
exists and renders XML if not. Most of the controllers will be
returning XML on some error or other so I''m including RenderError in
ApplicationController.
Is my approach a sound one? Also, is there a shorter and more
idiomatic way of writing this:
if @user.nil?
render_user_exists
2007 Jun 28
1
complete stumper: variable exists in hidden_field_tag, but nil everywhere else
This is a real mystery to me. I have an instance variable in a partial
that only gives its value inside a hidden_field_tag. If I try to use
the variable anywhere else in the partial, i either get nil or an
undefined error. The goal is to use the value of @event.id outside of
hidden_field_tag.
Here''s what works:
<%= hidden_field_tag ''id'', @event && @event.id,
2010 May 04
3
Idiomatic looping over list name, value pairs in R
Considering the python code:
for k, v in d.items(): do_something(k); do_something_else(v)
I have the following for R:
for (i in c(1:length(d))) { do_something(names(d[i]));
do_something_else(d[[i]]) }
This does not seem seems idiomatic. What is the best way of doing the
same with R?
Thanks.
Luis
2006 Feb 08
2
Idiomatic way to change partial''s behavior based on caller
Guys,
I have a partial that is shared by many controllers, and this partial
has a link that needs to do different things based on which controller
calls it.
So, the partial looks like this:
<!-- _part.rhtml -->
<tr>
<td><%=part.number%></td>
<td><%=part.associated_part_number%></td>
<td><%=part.drawings%></td>
2008 Feb 25
4
A more idiomatic way to write this
Hello,
I have a vector of 1,000,000 numbers and another vector of 1,000
divisors. What I'd like to do is to divide the first 1,000 numbers of
the first vector by the first divisor, then the next 1,000 by the second
divisor and so on. I came up with this, but I was wondering if there is
a more idiomatic, R-like way to write it:
x <- ...
divs <- ...
for (i in seq(from = 1, to = 1000000,
2006 Jan 17
2
Specify ID for a form?
Hi all,
I have a a really, really dumb Newb question... I am trying to use
observe_form to use AJAX calls in order to refresh a particular page
fragment using the form data.
I have run into a stumbling block very early on in the process - how can I
provide an ''id'' attribute to the form_remote_tag or start_form_tag methods?
Specifying something like :id =>
2006 Jun 30
4
More idiomatic way of writing a filter
Is there a more elegant way of writing this?
def verify_user
@user = User.find_by_username params[:username]
if @user.nil?
message = xml.error do |xm|
xm.message "User does not exists: #{params[:username]}"
end
render :xml => message
return false
else
true
end
end
Thanks, Joel
--
2011 Aug 20
4
[PATCH 1/2] Make xencommons a bit more idiomatic
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
diff -r 8d6edc3d26d2 -r cfb49fe940fd tools/hotplug/Linux/init.d/xencommons
--- a/tools/hotplug/Linux/init.d/xencommons Sat Aug 13 10:14:58 2011 +0100
+++ b/tools/hotplug/Linux/init.d/xencommons Tue Aug 16 16:56:16 2011 -0700
@@ -29,11 +29,9 @@
XENCONSOLED_PIDFILE=/var/run/xenconsoled.pid
shopt -s extglob
-if test
2007 Aug 23
4
Idiomatic way to do a non-database Enumeration?
I have a class which stores as one of its attributes a day of the week
as an integer (0-6, 0=Sunday, standard UNIXy values). I want,
obviously, the views to show the weekday name and the forms to provide
a drop-down with the weekday names. Essentially it''s a vrtual
attribute whose value is the localized weekday name, which maps to the
integer value that''s actually stored.
2020 Feb 19
1
[PATCH] golang: make API idiomatic so that functions return (<val>, error)
Go API functions returned (<val>, *GuestfsError) that made
code like this fail to build:
n, err := os.Stdin.Read(buf)
if err != nil {
log.Fatal(err)
}
n, err = g.Pwrite_device(dev, buf[:n], off)
...
As err should be of error (interface) type as of the stdlib call,
and should be of *GuestfsError type as of the libguestfs call.
The concrete error value that
2008 Oct 29
0
RJS problem after upgrading to Rails 2.0.2
I just updated an old app from 1.2.6 to 2.0.2 and I''m having an rjs problem.
I have one page that has 2 submit to remote buttons, one to do a price
override and the other to remove the lineitem. Everything is working
perfectly before the update but now the price override doesn''t update the
page. I''ve verified that the price_override method still gets called
because
2018 Jun 28
1
[nbdkit PATCH] main: More idiomatic use of getopt_long
Prefer named constants over magic numbers in the 'struct option'
list, and expand the list of enums for long-only options so that
the call to getopt_long() can switch directly to every option,
rather than needing a lengthy if/else chain that grows for every
new long option.
Patch best viewed with whitespace changes ignored.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
2010 Aug 26
1
[PATCH] Adding the ability to select a Host to start a VM
Signed-off-by: Simon COURTOIS <scourtois at linagora.com>
---
src/app/controllers/vm_controller.rb | 5 ++
src/app/models/vm_task.rb | 4 +-
src/app/views/vm/start.rhtml | 77 ++++++++++++++++++++++++++++++++++
src/task-omatic/taskomatic.rb | 7 +++-
4 files changed, 91 insertions(+), 2 deletions(-)
create mode 100644 src/app/views/vm/start.rhtml
diff
2006 Mar 04
3
select helper method
Hey
I''m having problems understanding the select helper. Here is my code:
_____________________
DB table: genres
id
name
descripition
___________________
In the controller:
def index()
@genres = Genre.find_all.map {|u|[u.name, u.id]}
@id = params[''genre'']
end
____________________
In the view:
<%
@genre = Genre.new
@genre.id = @id
%>
2009 Jan 10
2
hidden_field_tag flattens my array for value
ERB:
<%= hidden_field_tag(''users_ids'', @users.collect(&:id))%>
OUTPUT:
<input id="users_ids" name="users_ids" type="hidden"
2006 Apr 05
2
Overring hidden_field_tag ?
Hi, I wonder how to override some tag generators, for example the
hidden_field_tag function.
By the way, I would be interested to learn how to extend
ActionView::Base so new functions would be available to all my views
(functions that need _erbout access, so a simple helper doesn''t...help)
Thanks
--
Posted via http://www.ruby-forum.com/.