hi,
I''ve a problem with resource_feeder plugin, basically works fine until
we give nested resource url.
Basically: /blog/1/posts/2, named route: blog_post_url
This needs :blog_id and :id passed as a parameter, otherwise it cannot
work.
I''ve managed to go through some :link => lamda { |o| whatever.. }
in :feed and :item options, but I''ve got no luck.
Also I''ve tried to specify :url_rewriter option, but I come up with
nothing.
any help would be appreciated, thanks.
[...]
    @posts = BlogPost.find(:all, :order => ''created_at
DESC'', :limit
=> limit)
    options_for_feed = {
      :feed => { :title => "Latest #{limit} Blog Posts"},
      :item => { :description => :excerpt }
    }
    respond_to do |format|
      format.html
      format.rss  { render_rss_feed_for(@posts, options_for_feed) }
      format.atom { render_atom_feed_for(@posts, options_for_feed) }
    end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Hi Claudio,
This *may* work, it''s untested, completely off the top of my head,  
*and* it will only work to generate urls for records with existing  
ids (which your blog_posts do have).
In the lib directory create a file called blog_post_url_writer.rb  
with the following contents:
class BlogPostUrlWriter
   def initialize(controller)
     @controller = controller
   end
   def blog_post_url(blog_post)
     @controller.send :blog_post_url, blog_post.blog_id, blog_post
   end
end
Then, in your controller you do:
blog_post_url_writer = BlogPostUrlWriter.new(self)
and in your options_for_feed you add:
:url_writer => blog_post_url_writer
That *should* route the calls resource feeder makes to blog_post_url  
through your special BlogPostUrlWriter instance, which as you can see  
above, inserts the :blog_id into the call to the *real* blog_post_url  
helper.
HTH,
Trevor
On 30-Mar-07, at 4:54 AM, Claudio Poli  wrote:
>
> hi,
> I''ve a problem with resource_feeder plugin, basically works fine
until
> we give nested resource url.
>
> Basically: /blog/1/posts/2, named route: blog_post_url
>
> This needs :blog_id and :id passed as a parameter, otherwise it cannot
> work.
>
> I''ve managed to go through some :link => lamda { |o| whatever..
}
> in :feed and :item options, but I''ve got no luck.
> Also I''ve tried to specify :url_rewriter option, but I come up
with
> nothing.
>
> any help would be appreciated, thanks.
>
> [...]
>     @posts = BlogPost.find(:all, :order => ''created_at
DESC'', :limit
> => limit)
>     options_for_feed = {
>       :feed => { :title => "Latest #{limit} Blog Posts"},
>       :item => { :description => :excerpt }
>     }
>     respond_to do |format|
>       format.html
>       format.rss  { render_rss_feed_for(@posts, options_for_feed) }
>       format.atom { render_atom_feed_for(@posts, options_for_feed) }
>     end
>
>
> 
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
hi Trevor, thanks so much for this code, well written and I will test it soon as I can. thanks again. Claudio Il giorno 30/mar/07, alle ore 18:43, Trevor Squires ha scritto:> > Hi Claudio, > > This *may* work, it''s untested, completely off the top of my head, > *and* it will only work to generate urls for records with existing > ids (which your blog_posts do have). > > In the lib directory create a file called blog_post_url_writer.rb > with the following contents: > > class BlogPostUrlWriter > def initialize(controller) > @controller = controller > end > > def blog_post_url(blog_post) > @controller.send :blog_post_url, blog_post.blog_id, blog_post > end > end > > Then, in your controller you do: > > blog_post_url_writer = BlogPostUrlWriter.new(self) > > and in your options_for_feed you add: > > :url_writer => blog_post_url_writer > > That *should* route the calls resource feeder makes to blog_post_url > through your special BlogPostUrlWriter instance, which as you can see > above, inserts the :blog_id into the call to the *real* blog_post_url > helper. > > HTH, > Trevor > > On 30-Mar-07, at 4:54 AM, Claudio Poli wrote: > >> >> hi, >> I''ve a problem with resource_feeder plugin, basically works fine >> until >> we give nested resource url. >> >> Basically: /blog/1/posts/2, named route: blog_post_url >> >> This needs :blog_id and :id passed as a parameter, otherwise it >> cannot >> work. >> >> I''ve managed to go through some :link => lamda { |o| whatever.. } >> in :feed and :item options, but I''ve got no luck. >> Also I''ve tried to specify :url_rewriter option, but I come up with >> nothing. >> >> any help would be appreciated, thanks. >> >> [...] >> @posts = BlogPost.find(:all, :order => ''created_at DESC'', :limit >> => limit) >> options_for_feed = { >> :feed => { :title => "Latest #{limit} Blog Posts"}, >> :item => { :description => :excerpt } >> } >> respond_to do |format| >> format.html >> format.rss { render_rss_feed_for(@posts, options_for_feed) } >> format.atom { render_atom_feed_for(@posts, options_for_feed) } >> end >> >> >> > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 30, 6:43 pm, Trevor Squires <tre...-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote:> Hi Claudio, > > This *may* work, it''s untested, completely off the top of my head, > *and* it will only work to generate urls for records with existing > ids (which your blog_posts do have).[...] allright, now I''m not in hurry and I can write a complete response :) your code works wonderfully, and I''ll blog about it right now ( http://railswatcher.com ) giving you credit. For people that doesn''t want to bother reading the article here''s the code for controller: def index limit = 10 @posts = BlogPost.find(:all, :order => ''created_at DESC'', :limit => limit) blog_post_url_writer = BlogPostUrlWriter.new(self) options_for_feed = { :feed => { :title => "Latest #{limit} Blog Posts on iCoreTech.org", :link => "http://example.com" }, # remember to fill those fields, title, description and pub_date, I''ve encountered problems without. :item => { :title => :title, :description => :excerpt, :pub_date => :created_at }, :url_writer => blog_post_url_writer } respond_to do |format| format.html format.rss { render_rss_feed_for(@posts, options_for_feed) } format.atom { render_atom_feed_for(@posts, options_for_feed) } end end Thanks! Claudio --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---