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
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
hi Trevor,
thanks so much for this code, well written and I will test it soon as
I can.
thanks again.
Claudio
[...]
allright, now I'm not in hurry and I can write a complete response ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=12)
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