newbee Q's - I'm afraid

2 views
Skip to first unread message

walt

unread,
Apr 30, 2008, 5:07:08 AM4/30/08
to resources_controller
Hi Ian,

I found my way here - and want to leave my appraisals of your
brilliant r_c with this group :)

My infancy (with r_c) probably explains the subject of this post, but
anyways -

with this:
-------------------------

class ProjectsController < ApplicationController
inherit_views
end

class SmallProjectsController < ProjectsController
end

class Project < ActiveRecord::Base
# table holds type (for STI), name, project_cost, and a few other
attributes
belongs_to :partner
end

class SmallProject < Project
end

class Partner < ActiveRecord::Base
has_many :projects
end

class Customer < Partner
end

class Supplier < Partner
end
---------

I would like to ask you

- will customers/4/small_projects work?
- is customer_small_projects_url(resource) the correct notation?

How do I use will_paginate with r_c - is it at all possible?

Like I started out in the subject - a lot of newbee questions, I'm
afraid :(

Hope to hear from you :)

best regards,
Walther


ps. is the public lighthouse "draft" still up for grabs ( or will
github suffice?)

Ian White

unread,
Apr 30, 2008, 6:43:41 AM4/30/08
to resources_...@googlegroups.com
Hi Walt,

Welcome to the list

> - will customers/4/small_projects work?
It will if there's a :small_projects association on customers (you
could make one)
(Or, you could make your projects controller know about :type (and
override find/new_resource methods), and route :small_projects to
:projects, :type => 'small_project')

> - is customer_small_projects_url(resource) the correct notation?

It depends on your routes.rb,
This is just rails though, nothing to do with RC, resource is just a
method pointing to (in this case) a customer

> How do I use will_paginate with r_c - is it at all possible?

It should be - I have
Just change find_resources to something like this:

def find_resources
resource_service.paginate(options)
end

> ps. is the public lighthouse "draft" still up for grabs ( or will
> github suffice?)

Issue tracker (for bugs and patches, use this group for this sort of
request) is now at lighthouse

http://ianwhite.lighthouseapp.com/

Cheers,
Ian
--
Argument from Design--We build web applications
Western House 239 Western Road Sheffield S10 1LE UK
Mobile: +44 (0)797 4678409 | Office: +44 (0)114 2667712
<http://www.ardes.com/> | <http://blog.ardes.com/ian>

walt

unread,
Apr 30, 2008, 7:54:04 PM4/30/08
to resources_controller
Hi Ian,

sorry - I must have some SPAM filter engaged or-what-not - did not
receive any notification even though I signed up for this list <:)

anyways,

I dug up pagination_find - which somehow seemed to fit the bill - but
now I see your answer, and that will probably lure me into trying out
will_paginate once more :)

I've managed to do the index for /customers/4/small_projects - and
with a one-line patch to pagination_find, I'm able to do nested
pagination like /customers/4/small_projects/5/tasks?page=3

I know this is completely of track but this is what I "patches" into
pagination_find (or rather - the module Helpers) - not pretty and my
ruby illiteracy shines, but it gets me through <:)

def paginating_links(paginator, options = {}, html_options = {})
name = options[:name] || DEFAULT_OPTIONS[:name]
params = (options[:params] || DEFAULT_OPTIONS[:params]).clone
paginating_links_each(paginator, options) do |n|
params[name] = n
# was: link_to(n, params, html_options)
url = resources_url+"?#{name.to_s}="+n.to_s # changed
link_to(n, url, html_options) #
changed
end
end

Thank you so much for answering - and have a good one!

Walther



ps. should you ever find yourself "stranded" in Jutland or Denmark at
all, please give me a call - I would like to help you to a pint or two
of some of our danish brew (read: beer) :)

Ian White

unread,
May 1, 2008, 9:16:53 AM5/1/08
to resources_...@googlegroups.com
Hi Walt,

I don;t really know much about pagination_find, never used it.

the will_paginate answer might help you out though - basically treat
resource_service like a class or association

> ps. should you ever find yourself "stranded" in Jutland or Denmark at
> all, please give me a call - I would like to help you to a pint or two
> of some of our danish brew (read: beer) :)

Will do - always up for a beer

walt

unread,
May 2, 2008, 7:29:50 AM5/2/08
to resources_controller
Hi Ian,

the pagination_find is back on the shelf, and will_paginate churning
away with resource_service. Super!

next item on my todo is creating new projects.

on the SmallProjectsController, I'm able to do

def new
what.ever.needs.done
end

but if I leave out the def on SmallProjectsController, i get the
default action from resources_controller lib - not the action from the
ProjectsController

is that related to r_c - or just standard Rails/Ruby functionality
that you cannot inherit methods?

I've even tried

def new
super
end

on the SmallProjectsController, but that did not change anything <:(

Why not just def the methods on SmallProjectsController? Well, trying
to DRY my code, I'd sure like to keep as much code as possible on the
ProjectsController - with 8-10 ProjectsController subclassed
controllers on the horizon :)

Cheers
walt

Ian White

unread,
May 2, 2008, 7:50:40 AM5/2/08
to resources_...@googlegroups.com
Hi walt,

thanks for your birth advice/musings

If you have SmallProjectsController < ProjectsController
then you should get the inherited method - is that not happening?

2008/5/2 walt <wal...@diechmann.net>:

--

walt

unread,
May 2, 2008, 8:30:50 AM5/2/08
to resources_controller
Hi Ian,

my pleasure (and yours to be, I hope) :)

Well, that's just it - I thought, I'd read your docs carefully
through, and was expecting to get the ProjectsController#new method,
on my SmallProjectsController - but no!

It's probably the famous "comma" glitch that wreaked havoc on the
Apollo 11 ;)

Anyways, I've added my ProjectsController and SmallProjectsController
here - for everyone to "enjoy" (I mean, I'm so newbee on this rails
road) :))
- please correct me on the code in general, if you see "bad patterns"

class ProjectsController < ApplicationController #<
ResourceController::Base #

# perhaps transform_with_xsl needs this one?
require 'xml/xslt'

before_filter :login_required
after_filter :transform_with_xsl, :only => :display_invoice

resources_controller_for :projects
inherit_views

def find_resources
params[:perpage] ||= resource.per_page rescue
RECORDS_PER_PAGINATED_PAGE
params[:page] ||= 1
case params[:search]
when nil
resource_service.search("", params[:page], params[:perpage])
else
resource_service.search(params[:search], (params[:page] ),
( params[:perpage] ) )
end
end


def new
unless enclosing_resource.nil?
@partner_name = enclosing_resource.name
@contact = Contact.find_by_partner_id(enclosing_resource.id)
rescue "" #@project.contact.name rescue ""
else
@partner_name = ""
@contact = Contact.new
end
@new_contact_id = @contact.id rescue "0"
@project = Project.new
#@project.project_number = @project.get_next_project_number
end


def edit
@project = Project.find_by_id(params[:id]) or (render_404 and
return)
@project.contact_name = @project.contact.name rescue ""
@project.partner_name = @project.partner.name rescue ""
#@contact = @project.contact rescue ""
@new_contact_id = @project.contact.id rescue "0"
@project.delivery_at_date = show_date @project.delivery_at
end

-------clipped to spare you the ugly details :) -------
end

class SmallProjectsController < ProjectsController
#ResourceController::Base
before_filter :login_required

resources_controller_for :small_projects

end


Ian, it really is very good of you to take your time answering my dumb
questions, especially when I know that you ought to be with your wife!

Thank you very much!
walt

walt

unread,
May 2, 2008, 9:44:24 AM5/2/08
to resources_controller

Hi Ian,

I forgot to attach the config/routes.rb (clipped to topic at hand)

#map.resources :customers, :has_many =>
[ :projects, :small_projects, :invoices, :contacts]
map.resources :customers do |customer|
customer.resources :projects do |project|
project.resources :tasks do |task|
task.resources :jobs
end
end
customer.resources :small_projects do |small_project|
small_project.resources :tasks do |task|
task.resources :jobs
end
end
customer.resources :invoices do |invoice|
invoice.resources :invoice_items
end
customer.resources :contacts
end

As you might see from the above clipping, I've tried with
the :has_many way (it's Rails 2.0.2 - isn't it?) and with the :do way
(ol'school!?)

Cheers
walt

Ian White

unread,
May 2, 2008, 9:46:42 AM5/2/08
to resources_...@googlegroups.com
Hi walt,

You may have caught a bug (the inheritance issue) I check the spec
suite and make sure

Do you have the latest rc and egde? Or are you on 2.0.2

Cheers,
Ian


2008/5/2 walt <wal...@diechmann.net>:

--

walt

unread,
May 2, 2008, 3:52:01 PM5/2/08
to resources_controller

Hi Ian,

I'm on 2.0.2 - but I've been looking for an opportunity to ask
someone for quite a while what their opinion towards edge is (for
buildings apps meant to be put into production). Do you develop RoR
apps on edge - and deploy them on edge as well?

I installed the r_c on April 30th

BTW: do you know of a rake tast that will show the (git) version of
plugins?

Hope not to have spoiled the entire r_c with my STI'ing ;)

cheers
Walt


ps sorry for not replying faster - I had to dance lancier with my
daughter who will graduate this summer :)

Ian White

unread,
May 2, 2008, 4:53:08 PM5/2/08
to resources_...@googlegroups.com
Ok, you caught a bug (kinda) - thanks!
Basically, rc does lump in the rc actions over the top of what you;ve
already got

But a workaround is this (till it gets fixed)

(in subclassed controller, assuming that methods 'new', and 'create'
are defined in superclass, and you want them in the subclass)

class SmallProjectsController < ProjectsController
resources_controller_for ... , :except => [:new, :create]
end

Let me know how it works out

Cheers,
Ian

2008/5/2 walt <wal...@diechmann.net>:
>
>

--

walt

unread,
May 2, 2008, 8:40:13 PM5/2/08
to resources_controller
> Ok, you caught a bug (kinda) - thanks!

Ohh - I'm sorry <:)
(- was hoping to have just misspelled or overlooked some obvoius
argument, or what-have-i-not)

Anyways, I tried your

> resources_controller_for ... , :except => [:new, :create]

in my SmallProjectsController like this

class SmallProjectsController < ProjectsController
before_filter :login_required

resources_controller_for :small_projects, :except => [:new, :edit]

response_for :create do |format|
format.html { flash[:notice]="Tilbudet blev gemt korrekt!";
redirect_to resource_url }
end

response_for :update do |format|
format.html { flash[:notice]="Tilbudet blev opdateret korrekt!";
redirect_to resource_url }
end

response_for :destroy do |format|
format.html { flash[:notice]="Tilbudet blev slettet korrekt!";
redirect_to resources_url }
end

end

- and tried them with both routes definitions (the :has_many and
the :do, like I sent you last)

But, alas, no luck :(

I get a "no action responded to new"

My 2c on the topic would be that it seems like your include_action
method will undef the actions and that ruby mistakingly somehow undefs
"new" alltogether - as it is probably def'ed once the
SmallProjectsController is instantiated, and thus when "redef'ed"
later on by your include_actions - the method is lost alltogether.

One way of doing it - perhaps, I'm not at all up to par on this ruby
stuff - would be to rename/alias the CRUD class_methods on the
controller, in your module, and then call the renamed methods and when/
if failing, call your "private" default versions - but again, I'm not
at all to comment on these matters <:/

Cheers
walt

Ian White

unread,
May 3, 2008, 2:40:33 AM5/3/08
to resources_...@googlegroups.com
Hi Walt,

I was being a bit brain dead last night - what you want is this:
(in the subclass)

resources_controller_for ... :actions => false

Ian White

unread,
May 3, 2008, 6:03:35 AM5/3/08
to resources_...@googlegroups.com
Hi Walt,

So, hopefully :actions => false will have solved your problem, sorry
for leading you down the garden path with me previous post.

The next question is, is this behaviour correct, and least surprising?

At the very least the docs should probably be made clearer

Cheers,
Ian


2008/5/3 Ian White <ian.w...@gmail.com>:

--

walt

unread,
May 3, 2008, 2:53:21 PM5/3/08
to resources_controller
Hi Ian,

no problem :)

- and yes, affirmative: the SmallProjectsController now reverts to the
actions on the ProjectsController :)

right now I'm refitting my controllers to the r_c - most of them was
using your "competalleaque" 's resource_controller (Mr Golick, if I'm
not mistaken) - so I'll be a little while before I can confirm that
the r_c works 100% :)

I like to think that your implementation is cleaner, faster and
certainly requires less LOC's - and that always loooks good on the
stats, right? :)

The :actions => false will require me to implement all actions on the
inherited class (ProjectsController) - or can I mix in one/two actions
with special requirements on the child class
( SmallProjectsController) ?

I use response_for - if that will influence your answer :)

(this post just prooves (ehh is that with one/two o's?) that if you
hand the Devil one finger, he'll eat his way up your entire arm -
danish proverb, I'm not sure it translates very well into english) :))

But the point is that, now that I've got the #new action to play on
STI controllers, then off cause I'd like to start speicalizing
them :))

Cheers
walt

walt

unread,
May 3, 2008, 3:28:37 PM5/3/08
to resources_controller
Hi Ian,

I was just reading http://coderrr.wordpress.com/2008/03/ when I
stumbled over him? mentioning a bug in ruby 1.8 - where methods def'ed
in modules will not allow calling super. Could that be part of the
problem?

just a thought -

Cheers
walt

ps. if I can help out, please say the word :)
Reply all
Reply to author
Forward
0 new messages