Displaying 20 results from an estimated 100 matches similar to: "Extending AR::B to provide translations"
2005 Mar 06
12
Where to place custom classes?
Hi all,
I am writing a simple shopping cart which will consist of a single
class. There will be no DB table for carts so I do not want to make my
Cart a model. But where do I place my Cart class so that I can access
it in my controllers?
I want to be able do do things like this (for instance in a shop
controller):
def add_to_cart
@session[''cart''].add(article_id, amount)
2005 Mar 06
4
has_many and order
Hi all,
if I have a has_many and belongs_to relations like this
category has many articles
article belongs to category
is there a way I can specify the order of articles when pulling them up
with
@some_category.articles
?
Many thanks in advance!
-- Nicky
2006 Apr 10
0
Inheriting data from one model to another
Hello
I''ve been struggling with something for hours that I thought would be
a simple job. Hopefully somebody can shed some light on what I''m
trying to do :o)
First of all I''ll explain what I''m trying to achieve. In a store
application I want to have products and product variations. A product
variation should inherit all of its properties from product unless
2007 Mar 04
4
Rails functional testing and Mocha
I''ve always wanted to be able to do stuff like this in my functional
tests
c = customers(:customer_1)
c.expects(:great_customer_service)
post :service_customer, :id => c.id
This of course fails because inside the rails action a different
instance of customer is used. Some of the time setting your
expectation/stubbing on Customer.any_instance works, but it''s not
2006 Aug 09
2
How do you define a method
Hi all,
I was wondering if anybody could help me figure why a view cannot find a
method that I defined in another class. I do this in the view: (let''s
say index.rhtml)
<%= check_box("item_search_page", "method_name")
Here, item_search_page is a variable in the view''s controller, which
creates a new ItemSearchPage object. And I defined
2007 Aug 08
1
Mocking Time, delegating to original object
In my Unit tests, I run into the all-too-common problem of
Time.expects(:now) being called by Benchmark before the method is
unmocked.
Instead of messing around with the teardown order, I decided to modify
the Expectation with a new method, .stops_mocking.
Here are the changes I use, including a few monkey patches to push
relevant objects down to where I want them, all wrapped up in a big
ugly
2007 Jan 02
4
allow stubbing of previously defined methods such as "id"
On my current project I needed to create a stub that responded
correctly to the id message. Here''s the change I put into my copy of
head.
Index: lib/mocha/mock_methods.rb
===================================================================
--- lib/mocha/mock_methods.rb (revision 1114)
+++ lib/mocha/mock_methods.rb (working copy)
@@ -68,6 +68,7 @@
method_names =
2006 Aug 06
0
view cannot see the method...:(
Hi all,
I just can''t figure why the view cannot find a method that I defined in
another class. I do this in the view:
<%= check_box("item_search_page", "method_name")
Here, item_search_page is a variable in the controller, which creates a new
ItemSearchPage object.
class ItemSearchPage
def method_name
end
end
So, although I defined it and it''s
2007 Mar 30
7
problem with using any_instance
Hey all,
I have a question with using mocha in my tests.
In the same test file, I have two tests,
<code>
def test_a
klass.any_instance.stubs(:method_name).returns("something")
klass.new.method_name
...
end
def test_b
...
klass.new.method_name
...
end
</code>
where klass is some class
when the tests run, test _a passes, but test_b had an error like this:
2009 May 06
1
How to extend ActionMailer
I wish to extend ActionMailer::Base by method chaining a class instance
variable:
module ActionMailer
class Base
class << self
def method_name
...
What is the magic incantation to accomplish this?
I cannot get this to work with action mailer:
module MyMethods
def self.include(base)
base.alias_method_chain :method_name, :my_method
def
2009 Apr 13
4
Creating Methods in the Model?
Hey Everyone.
First day diving in to ROR and Ruby...
My question is how do you define methods with in the model class and/or
should I even be doing this?
It is my understanding that you should put as much of the business logic
into the model as possible. I want to do some data manipulation before
I things are submitted to the database
IE (Create a variable out of two submitted via form, as
2006 Aug 06
2
help with method_missing in ActiveRecord
I am serializing a data object (FooData) into an ActiveRecord column (Foo).
I''d like to be able to do delegate methods to the data class if the Foo
class doesn''t have that attribute. So instead of:
f = Foo.new
f.data.item1
I''d like to do:
f = Foo.new
f.item1
I was hoping that I could add a method_missing method to my Foo class and
call methods in the FooData class
2007 May 21
0
[1025] trunk/wxruby2/swig: Use Wx::THE_APP constant as global reference to App (as per WxWidgets);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding:
2007 Dec 08
6
Rails 2.0 ActionMailer breaks my redmine render_message
I am using ''redmine'' (v 0.6) as my major project manager, seems running
fine w Rails 2.0 (slight modifs for paginations..) but I am stuck with a
major error when sending a confirmation email :
mailer.rb
class Mailer < ActionMailer::Base
....
# Renders a message with the corresponding layout
def render_message(method_name, body)
layout =
2012 Feb 17
0
HtmlSlicer 0.0.1
How to split HTML content?
Well, the text like:
<p>Ruby on Rails is a next-generation web-framework<br><b>YEAH!</b>And of course Java killer?! :) ©</p>
You can split to a pages in a smart way.
I tried to realize it in a gem for my internal use, and now when it works for my Rails 3.1.3 application, this is enough to make it public.
I
2006 Sep 22
2
foo.expects(:blah).returns(10).then(11) syntax
I recently needed the behavior of my object to change on subsequent
method calls so I added the syntax above.
Here''s the diff of changes I made:
Index: test/mocha/expectation_test.rb
===================================================================
--- test/mocha/expectation_test.rb (revision 854)
+++ test/mocha/expectation_test.rb (working copy)
@@ -95,6 +95,12 @@
2019 Aug 23
2
[nbdkit PATCH 3/3] plugins: Add .can_fast_zero hook
Allow plugins to affect the handling of the new NBD_CMD_FLAG_FAST_ZERO
flag, then update affected plugins. In particular, in-memory plugins
are always fast; the full plugin is better served by omitting .zero
and relying on .pwrite fallback; nbd takes advantage of libnbd
extensions proposed in parallel to pass through support; and
v2 language bindings expose the choice to their scripts.
The
2007 Oct 29
2
rspec throws exception (nameError)
Hi,
I''m running Rails 1.2.5 with rspec 1.0.8.
When i runned autotest first time, it complained about this line.
#include ActionView::Helpers::JavaScriptMacrosHelper
in vendor/plugins/rspec_on_rails/lib/spec/rails/dls/behaviour/helper.rb
...I commented it out, then I got another error about this line, so I
also commented this out.
#Test::Unit.run = true
in
2006 Feb 05
0
How can i specify default time to datetime_select tag
I want to specify a different default time to datetime_select tag how
can i do that.
also i was looking at rails helper code
-----------------------------------------------------------------------
module ActionView
module Helpers
module DateHelper
def to_datetime_select_tag(options = {})
defaults = { :discard_type => true }
options = defaults.merge(options)
2007 Dec 14
0
async-observer rails plugin
I''m pleased to announce the existence of async-observer.
This is the very first public release. In the future I''ll confine
announcements to the beanstalk-talk mailing list.
WHAT IS ASYNC OBSERVER?
-----------------------
Async Observer is a Rails plugin that provides deep integration with
Beanstalk.
beanstalkd is a fast, distributed, in-memory work-queue service. Its