apotonick/apotomo — Issue #67: url_for_event does not work with nested routes.
Author: bradphelan
Created: 2012-02-15 12:46:12+00:00
State: open

Say I have an meeting management website. To access a meeting you go to URL

http://meeting.com/meeting/1

and you are presented with the web interface for a meeting with **id = 1**. Each meeting can have a comments thread and the comments thread is embedded within an Apotomo cell. All is good :). My meetings controller is

class EventsController < ApplicationController
respond_to :html, :js

# CANCAN should load the resource
load_resource :only => :render_event_response

has_widgets do |root|
root << panel = widget("comments/panel", :comments, :meeting => @meeting)
end

...
end

The @meeting object is loaded via CANCA and passed to the main widget. However I now have a problem in that I wish to have an Apotomo event called for deleting a comment. In my view I create a link for my delete button.

= link_to url_for_event(:destroy,
:source => widget_id,
:id => @meeting.id,
:comment_id => comment.id),
remote: true

The extra parameter ** :id => @meeting.id** should not be necessary as url_for_event is being called in the context of **http://meeting.com/meeting/1** and the url should either be generated as

http://meeting.com/meeting/1/render_event_response?.... params ...

or

http://meeting.com/meeting/render_event_response?id=1&....params....

or am I doing something totally back to front here. Having to put the

:id => @meeting.id,

explicity in the call to url_for_event is breaking encapsulation as **meeting** should be passed into the widget from the top level.