Ah, sorry. I've now deleted everything from my Recommendations
controller:
class Recommendations < Application
# provides :xml, :yaml, :js
controlling :recommendations do |r|
r.belongs_to :user
end
end # Recommendations
However, that still lists all the recommendations in both cases. I
have this in my index.html.erb:
<div>
<ul>
<%= partial :recommendation, :as => :recommendation, :with =>
@recommendations %>
</ul>
</div>
And the partial:
<%= tag(:li, "#{recommendation.user.name} recommends #
{recommendation.recommendee.name}") %>
Balint
On Dec 4, 12:30 pm, "Martin Gamsjaeger" <[EMAIL PROTECTED]> wrote:
> Balint,
>
> You *don't* need to specify *any* action code at all! From your given
> example, if you have
>
> # inside config/router.rb
> Merb::Router.prepare do
> resources :recommendations do
> resources :users do
> resources :recommendations
> end
> end
>
> # inside app/controllers/application.rb
> class Application < Merb::Controller
> extend Merb::ResourceController::Mixin::ClassMethods
> end
>
> # inside app/controllers/recommendations.rb
> class Recommendations < Application
> controlling :recommendations do |r|
> r.belongs_to :user
> end
> end
>
> This should do all you need !?! Let me know if it doesn't or if you
> mean something different!
>
> cheers
> snusnu
>
> On Thu, Dec 4, 2008 at 8:02 AM, baaz <[EMAIL PROTECTED]> wrote:
>
> > Hi Martin,
>
> > I managed to make it work with a little trick. Instead of adding a
> > line into the dependencies.rb I inserted a require
> > "merb_resource_controller" into init.rb. I am sure this is not clean
> > but at least merb starts.
>
> > So I tried to rewrite the index action of my Recommendations
> > controller that had looked like this:
>
> > def index
> > find_opts = {}
> > find_opts[:user_id] = params[:user_id] unless params
> > [:user_id].nil?
> > [EMAIL PROTECTED] = Recommendation.all(find_opts)
> > display @recommendations
> > end
>
> > I expected the code to "magically" (thanks to your plugin) know what
> > @recommendations should be set to based on the URL. So it would set it
> > to all recommendations for "/recommendations" (1) and to the
> > recommendations of the user for "/users/1/recommendations" (2). So I
> > wrote that:
>
> > def index
> > [EMAIL PROTECTED] = Recommendation.all
> > display @recommendations
> > end
>
> > But that loaded all the recommendations in both of the above cases. I
> > also tried the following method since if I understood you correctly an
> > instance variable @user is set to the actual user in the (2) case:
>
> > def index
> > [EMAIL PROTECTED] = @user ? @user.recommendations :
> > Recommendation.all
> > display @recommendations
> > end
>
> > This did not work and after a very short debugging session I realized
> > that the @user variable is nil in both cases. (I included the
> > "controlling" calls in my controllers as you described). Did I
> > understand you correctly? Is that how it should work?
>
> > Here are the versions I am running (as you very well suggested on your
> > blog):
>
> > Darwin balint-erdis-macbook.local 9.5.0 Darwin Kernel Version 9.5.0
> > ruby 1.8.6 (2008-03-03 patchlevel 114)
> > mysql Ver 14.12 Distrib 5.0.45
> > I am using 1.0.1 of all merb gems and 0.9.7 of all dm gems.
>
> > Once again, thank you for your help!
> > Balint
>
> > On Dec 3, 7:18 pm, "Martin Gamsjaeger" <[EMAIL PROTECTED]> wrote:
> >> Hmm,
>
> >> I must admit I haven't yet tried it inside the local gems dir, I only
> >> have it installed systemwide so far.
>
> >> One thing you could try is:
>
> >> inside irb:
> >> require "rubygems"
> >> require "merb_resource_controller"
>
> >> obviously this will only affect your systemwide installation and
> >> doesn't take into account the bundled gems,
> >> but it should show you a more precise error message! actually i think
> >> that once you have it working from systemwide gems, it should also
> >> work the bundled way.
>
> >> Out of interest, which version of merb/dm do you use?
>
> >> cheers
> >> snusnu
>
> >> On Wed, Dec 3, 2008 at 7:13 PM, baaz <[EMAIL PROTECTED]> wrote:
>
> >> > My bad, thank you, I fixed that in the dependencies.rb file.
>
> >> > However it does not change a lot. I installed the gem both into the
> >> > merb app's gems folder (first) and then to the default gems
> >> > repository. I always get the same thing:
>
> >> > FATAL: The gem merb_resource_controller (>= 0, runtime), [] was not
> >> > found
> >> > FATAL: The file merb_resource_controller was not found
>
> >> > Do I have to require it somewhere else maybe?
>
> >> > Balint
>
> >> > On Dec 3, 6:50 pm, "Martin Gamsjaeger" <[EMAIL PROTECTED]> wrote:
> >> >> Balint,
>
> >> >> The gem is named "merb_resource_controller" !
>
> >> >> So you should have:
>
> >> >> dependency "merb_resource_controller"
>
> >> >> instead of:
>
> >> >> dependency "merb_resourceful_controller"
>
> >> >> Let me know if this solves all your issues!
>
> >> >> cheers
> >> >> snusnu
>
> >> >> On Wed, Dec 3, 2008 at 5:15 PM, baaz <[EMAIL PROTECTED]> wrote:
>
> >> >> > Hey Martin,
>
> >> >> > That sounds great! I would love to give it a try but I could not
> >> >> > figure out how to install a plugin for Merb. I guess from this post
> >> >> > (http://blog.antarestrader.com/?p=70) that it might not happen so
> >> >> > smoothly. Standing in the root directory of my Merb app I did:
>
> >> >> > gem install snusnu-merb_resource_controller -i ./gems/
>
> >> >> > which installed your gem and all its dependencies into the 'gems'
> >> >> > directory. I added the following line to dependencies.rb below all the
> >> >> > others:
>
> >> >> > dependency "merb_resourceful_controller"
>
> >> >> > After that, when I started merb I received the following error:
>
> >> >> > FATAL: The gem merb_resourceful_controller (>= 0, runtime), [] was not
> >> >> > found
>
> >> >> > (I tried the same with "snusnu-merb_resourceful_controller" to no
> >> >> > avail.)
>
> >> >> > I also read Yehuda's guide (http://yehudakatz.com/2007/09/19/merb-
> >> >> > plugins-oh-yeah-theyre-pretty-frickin-cool-too/) -somewhat old- about
> >> >> > how to install a Merb-plugin and that seemed to be consistent with
> >> >> > what I do but I am surely missing soemthing.
>
> >> >> > If that's an easy one, could you point me to what I am doing wrong?
>
> >> >> > Thanks a lot!
> >> >> > Balint
>
> >> >> > On Dec 3, 2:34 am, "Martin Gamsjaeger" <[EMAIL PROTECTED]> wrote:
> >> >> >> Hey Balint,
>
> >> >> >> Unless I misunderstand something
> >> >> >> important,http://github.com/snusnu/merb_resource_controller/tree/mastermaywell
> >> >> >> be an option?
>
> >> >> >> It basically knows how to CRUD under different nesting strategies
> >> >> >> (i.e. /recommendations vs. /users/1/recommendations).
>
> >> >> >> It will always load your resource properly scoped (i.e.
> >> >> >> Recommendation.all vs. @user.recommendations), without any before
> >> >> >> filter abusing.
>
> >> >> >> It will also setup all the instance variables you would expect to
> >> >> >> find
> >> >> >> for use in your views (i.e. @recommendations vs. @user AND
> >> >> >> @recommendations)
>
> >> >> >> You would use it like so:
>
> >> >> >> class Application < Merb::Controller
> >> >> >> extend Merb::ResourceController::Mixin::ClassMethods
> >> >> >> end
>
> >> >> >> class Users < Application
> >> >> >> controlling :users
> >> >> >> end
>
> >> >> >> class Recommendations < Application
> >> >> >> controlling :recommendations do |r|
> >> >> >> r.belongs_to :user
> >> >> >> end
> >> >> >> end
>
> >> >> >> Maybe this helps? Let me know if anything doesn't work the way you
> >> >> >> expect, if you try it out. Also don't be afraid to dive into the
> >> >> >> code,
> >> >> >> read it (and the specs), fork it, throw it away, whatever ... It
> >> >> >> currently does a nice job for me! Let's make it better by using it
> >> >> >> more :-)
>
> >> >> >> That said, I'm all for Justin's suggestions to separate the
> >> >> >> controllers when needed! If the only thing is avoiding nasty
> >> >> >> conditionals for scoping queries and redirecting though, this may be
> >> >> >> a
> >> >> >> reasonably easy alternative ...
>
> >> >> >> cheers
> >> >> >> snusnu
>
> >> >> >> On Tue, Dec 2, 2008 at 8:24 PM, Justin Reagor <[EMAIL PROTECTED]>
> >> >> >> wrote:
> >> >> >> > On Dec 2, 2008, at 1:47 PM, baaz wrote:
>
> >> >> >> > Clearly, the data I should show in these two cases is different, so
> >> >> >> > the controller code should handle this somehow.
> >> >> >> > The "create" action in the controller is even messier, redirecting
> >> >> >> > to
> >> >> >> > different URLs depending on where we came from, etc. These
> >> >> >> > dual-duty
> >> >> >> > controllers will be bloated and not nice.
>
> >> >> >> > I think you nailed it on the head yourself, sounds like two
> >> >> >> > different
> >> >> >> > resources to me. Regardless of what the data model looks like on
> >> >> >> > the back
> >> >> >> > end, the exposed resources through the public API are probably
> >> >> >> > going to need
> >> >> >> > separate controllers.
> >> >> >> > Unless I'm misinterpreting what your trying to achieve here.
> >> >> >> > :: Justin Reagor
> >> >> >> > :: [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---