Message from discussion
Confused about how routes are supposed to be used
Received: by 10.52.32.66 with SMTP id g2mr6547342vdi.5.1334933186386;
Fri, 20 Apr 2012 07:46:26 -0700 (PDT)
X-BeenThere: batmanjs@googlegroups.com
Received: by 10.220.219.141 with SMTP id hu13ls1697554vcb.8.gmail; Fri, 20 Apr
2012 07:46:24 -0700 (PDT)
Received: by 10.52.33.47 with SMTP id o15mr581553vdi.9.1334933184787;
Fri, 20 Apr 2012 07:46:24 -0700 (PDT)
Date: Fri, 20 Apr 2012 07:46:23 -0700 (PDT)
From: luxerama <vinc...@siebert.im>
To: batmanjs@googlegroups.com
Message-ID: <12490746.2.1334933184085.JavaMail.geo-discussion-forums@vbez18>
In-Reply-To: <8B6859F3-2814-42BC-B68F-490AEACBD316@mac.com>
References: <6627045.1843.1332990034251.JavaMail.geo-discussion-forums@vbyj26>
<20879392.295.1334920767677.JavaMail.geo-discussion-forums@vbli11>
<8B6859F3-2814-42BC-B68F-490AEACBD316@mac.com>
Subject: Re: [batmanjs] Re: Confused about how routes are supposed to be
used
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_0_7369521.1334933184052"
------=_Part_0_7369521.1334933184052
Content-Type: multipart/alternative;
boundary="----=_Part_1_26267423.1334933184052"
------=_Part_1_26267423.1334933184052
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
This is not meant for API endpoins, so there is in REST nor CRUD involved.
I get your point if I was to, lets say create a CMS. The routeTo filter is
to be used when creating a batman.js application in order to achieve things
such as pretty URLs.
For example, I have a post which has a collection of attachments. Now
each attachment should have its on URL within the post like so *
/posts/post-identifier/attachements/attachement-identifier*. This would
require me to have a URL with multiple arguments like the ones described in
the examples.
I'm not sure if I have understood your argument completely, however I
cannot see this requirement to be anything out of the ordinary nor can I
see it breaking any conventions. The REST endpoints will all stay the same,
thus rails will be happy.
On Friday, 20 April 2012 14:24:20 UTC+1, anderson_f wrote:
>
> It sounds like you're fighting the framework. Resources imply a RESTful
> design where the http verbs imply the appropriate CRUD action. Instead of
> using a 'new' action, you should do a POST to '/foos'
>
> If you truly want it to route to a custom 'new' controller action I would
> suggest just using a @route statement in the app. However, for CRUD
> operations, you would be breaking RESTful design best practices if you care
> about that sort of thing.
>
> Here is a link explaining how Rails Routes and Resources work:
> http://guides.rubyonrails.org/routing.html
>
> Sent from my iPhone
>
> On Apr 20, 2012, at 7:19 AM, luxerama wrote:
>
> For anyone interested, I have created a helper that should be able to deal
> with most routing applications that are not covered by the tools provided
> by batman.js itself.
>
> https://gist.github.com/2422262
>
> Please let me know if you have any questions/improvements or found
> problems with it.
>
> On Thursday, 29 March 2012 04:00:34 UTC+1, Matt Zukowski wrote:
>>
>> I'm super confused about how I'm supposed to be using routes in my views.
>>
>> For example, I have this in my app.coffee:
>>
>> class MyApp extends Batman.App
>> @global yes
>>
>> @controller 'foos'
>> @model 'foo'
>> @resources 'foos'
>>
>>
>> Then under views/foos/index.html, I want to have a link that points to
>> the "new" form. I've seen all of the following in examples:
>>
>> <a data-route="foos#new">Add Foo</a>
>> <a data-route="routes.foos.new">Add Foo</a>
>> <a data-route="/foos/new">Add Foo</a>
>>
>>
>> But none of these work. I just get <a href="#">Add Foo</a>. The only one
>> I've managed to actually get working is:
>>
>> <a data-route="{'controller':'foos','action':'new'}">Add Foo</a>
>>
>> Seems kind of awkward, but whatever.
>>
>> Now I'm trying to add a link to the "edit" form for each Foo. And I can't
>> get this to work at all. I've tried:
>>
>> <div data-foreach-foo="Foo.all">
>> <a data-route="{'controller':'foos','action':'edit','id':foo.id}">Foo</a>
>> <a data-route="{'controller':'foos','action':'edit','id':id}"
>> data-bind-id='foo.id'>Foo</a>
>> <a data-route="routes.foos[foo].edit">Foo</a>
>> </div>
>>
>>
>> ... but no dice. Something feels really wrong here. Am I doing something
>> wrong?
>>
>> I'm using the latest batman.js installed from GitHub.
>>
>
------=_Part_1_26267423.1334933184052
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
This is not meant for API endpoins, so there is in REST nor CRUD involved. =
I get your point if I was to, lets say create a CMS. The routeTo filter is =
to be used when creating a batman.js application in order to achieve things=
such as pretty URLs.<div>For example, I have a post which has a collection=
of attachments. Now each attachment should have its on URL =
within the post like so <i>/posts/post-identifier/attachements/attachement-=
identifier</i>. This would require me to have a URL with multiple arguments=
like the ones described in the examples.</div><div><br></div><div>I'm not =
sure if I have understood your argument completely, however I cannot see th=
is requirement to be anything out of the ordinary nor can I see it breaking=
any conventions. The REST endpoints will all stay the same, thus rails wil=
l be happy.<br><br>On Friday, 20 April 2012 14:24:20 UTC+1, anderson_f wro=
te:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;=
border-left: 1px #ccc solid;padding-left: 1ex;"><div bgcolor=3D"#FFFFFF"><d=
iv>It sounds like you're fighting the framework. Resources imply a RESTful =
design where the http verbs imply the appropriate CRUD action. Instead of u=
sing a 'new' action, you should do a POST to '/foos'</div><div><br></div><d=
iv>If you truly want it to route to a custom 'new' controller action I woul=
d suggest just using a @route statement in the app. However, for CRUD opera=
tions, you would be breaking RESTful design best practices if you care abou=
t that sort of thing.</div><div><br></div><div>Here is a link explaining ho=
w Rails Routes and Resources work: <a href=3D"http://guides.rubyonrails.org=
/routing.html" target=3D"_blank">http://guides.rubyonrails.org/<wbr>routing=
.html</a><br><br>Sent from my iPhone</div><div><br>On Apr 20, 2012, at 7:19=
AM, luxerama wrote:<br><br></div><div></div><blockquote type=3D"cite"><div=
>For anyone interested, I have created a helper that should be able to deal=
with most routing applications that are not covered by the tools provided =
by batman.js itself.<div><br></div><div><a href=3D"https://gist.github.com/=
2422262" target=3D"_blank">https://gist.github.com/<wbr>2422262</a></div><d=
iv><br></div><div>Please let me know if you have any questions/improvements=
or found problems with it.<br><br>On Thursday, 29 March 2012 04:00:34=
UTC+1, Matt Zukowski wrote:<blockquote class=3D"gmail_quote" style=3D"mar=
gin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">I'm su=
per confused about how I'm supposed to be using routes in my views.<div><br=
></div><div>For example, I have this in my <font face=3D"'courier new', mon=
ospace">app.coffee</font>:</div><div><br></div><div><div style=3D"backgroun=
d-color:rgb(250,250,250);border-top-color:rgb(187,187,187);border-right-col=
or:rgb(187,187,187);border-bottom-color:rgb(187,187,187);border-left-color:=
rgb(187,187,187);border-top-style:solid;border-right-style:solid;border-bot=
tom-style:solid;border-left-style:solid;border-top-width:1px;border-right-w=
idth:1px;border-bottom-width:1px;border-left-width:1px;word-wrap:break-word=
"><code><div><span style=3D"color:#008">class</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">MyApp</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">extends</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#606">Batman</span><span style=3D"co=
lor:#660">.</span><span style=3D"color:#606">App</span><span style=3D"color=
:#000"><br> </span><span style=3D"color:#066">@global</span><span sty=
le=3D"color:#000"> yes<br><br> </span><span style=3D"color:#066">@con=
troller</span><span style=3D"color:#000"> </span><span style=3D"color:#080"=
>'foos'</span><span style=3D"color:#000"><br> </span><span style=3D"c=
olor:#066">@model</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#080">'foo'</span><span style=3D"color:#000"><br> </span><span s=
tyle=3D"color:#066">@resources</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#080">'foos'</span></div></code></div><div><br></div></di=
v><div><br></div><div>Then under views/foos/index.html, I want to have a li=
nk that points to the "new" form. I've seen all of the following in example=
s:</div><div><br></div><div style=3D"background-color:rgb(250,250,250);bord=
er-top-color:rgb(187,187,187);border-right-color:rgb(187,187,187);border-bo=
ttom-color:rgb(187,187,187);border-left-color:rgb(187,187,187);border-top-s=
tyle:solid;border-right-style:solid;border-bottom-style:solid;border-left-s=
tyle:solid;border-top-width:1px;border-right-width:1px;border-bottom-width:=
1px;border-left-width:1px;word-wrap:break-word"><code><div><span style=3D"c=
olor:#008"><a</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#606">data-route</span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#080">"foos#new"</span><span style=3D"color:#008">></span><spa=
n style=3D"color:#000">Add Foo</span><span style=3D"color:#008"></a><=
/span><span style=3D"color:#000"><br></span><span style=3D"color:#008"><=
a</span><span style=3D"color:#000"> </span><span style=3D"color:#606">data-=
route</span><span style=3D"color:#660">=3D</span><span style=3D"color:#080"=
>"routes.foos.new"</span><span style=3D"color:#008">></span><span style=
=3D"color:#000">A<wbr>dd Foo</span><span style=3D"color:#008"></a></s=
pan><span style=3D"color:#000"><br></span><span style=3D"color:#008"><a<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#606">data-ro=
ute</span><span style=3D"color:#660">=3D</span><span style=3D"color:#080">"=
/foos/new"</span><span style=3D"color:#008">></span><span style=3D"color=
:#000">Add Foo</span><span style=3D"color:#008"></a></span></div></co=
de></div><div><br></div><div><br></div><div>But none of these work. I just =
get <font face=3D"'courier new', monospace"><a href=3D"#">Add Foo<=
/a></font>. The only one I've managed to actually get working is:</div><=
div><br></div><div><div style=3D"background-color:rgb(250,250,250);border-t=
op-color:rgb(187,187,187);border-right-color:rgb(187,187,187);border-bottom=
-color:rgb(187,187,187);border-left-color:rgb(187,187,187);border-top-style=
:solid;border-right-style:solid;border-bottom-style:solid;border-left-style=
:solid;border-top-width:1px;border-right-width:1px;border-bottom-width:1px;=
border-left-width:1px;word-wrap:break-word"><code><div><span style=3D"color=
:#008"><a</span><span style=3D"color:#000"> </span><span style=3D"color:=
#606">data-route</span><span style=3D"color:#660">=3D</span><span style=3D"=
color:#080">"{'controller':'<wbr>foos','action':'new'}"</span><span style=
=3D"color:#008">></span><span style=3D"color:#000">Add Foo</span><span s=
tyle=3D"color:#008"></a></span></div></code></div></div><div><br></di=
v><div>Seems kind of awkward, but whatever.</div><div><br></div><div>Now I'=
m trying to add a link to the "edit" form for each Foo. And I can't get thi=
s to work at all. I've tried:</div><div><br></div><div style=3D"background-=
color:rgb(250,250,250);border-top-color:rgb(187,187,187);border-right-color=
:rgb(187,187,187);border-bottom-color:rgb(187,187,187);border-left-color:rg=
b(187,187,187);border-top-style:solid;border-right-style:solid;border-botto=
m-style:solid;border-left-style:solid;border-top-width:1px;border-right-wid=
th:1px;border-bottom-width:1px;border-left-width:1px;word-wrap:break-word">=
<code><div><span style=3D"color:#008"><div</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#606">data-foreach-foo</span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#080">"Foo.all"</span><span =
style=3D"color:#008">></span><span style=3D"color:#000"><br></span><span=
style=3D"color:#008"><a</span><span style=3D"color:#000"> </span><span =
style=3D"color:#606">data-route</span><span style=3D"color:#660">=3D</span>=
<span style=3D"color:#080">"{'controller':'<wbr>foos','action':'edit','id':=
<a href=3D"http://foo.id" target=3D"_blank">foo<wbr>.id</a>}"</span><span s=
tyle=3D"color:#008">></span><span style=3D"color:#000">Foo</span><span s=
tyle=3D"color:#008"></a></span><span style=3D"color:#000"><br></span>=
<span style=3D"color:#008"><a</span><span style=3D"color:#000"> </span><=
span style=3D"color:#606">data-route</span><span style=3D"color:#660">=3D</=
span><span style=3D"color:#080">"{'controller':'<wbr>foos','action':'edit',=
'id':id}<wbr>"</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#606">data-bind-id</span><span style=3D"color:#660">=3D</span><span style=
=3D"color:#080">'<a href=3D"http://foo.id" target=3D"_blank">foo.id</a>'</s=
pan><span style=3D"color:#008">></span><span style=3D"color:#000">Foo</s=
pan><span style=3D"color:#008"></a></span><span style=3D"color:#000">=
<br></span><span style=3D"color:#008"><a</span><span style=3D"color:#000=
"> </span><span style=3D"color:#606">data-route</span><span style=3D"color:=
#660">=3D</span><span style=3D"color:#080">"routes.foos[foo].<wbr>edit"</sp=
an><span style=3D"color:#008">></span><span style=3D"color:#000">Foo</sp=
an><span style=3D"color:#008"></a></span><span style=3D"color:#000"><=
br></span><span style=3D"color:#008"></div></span></div></code></div>=
<div><br></div><div><br></div><div>... but no dice. Something feels really =
wrong here. Am I doing something wrong?</div><div><br></div><div>I'm using =
the latest batman.js installed from GitHub.</div></blockquote></div></div><=
/blockquote></div></blockquote></div>
------=_Part_1_26267423.1334933184052--
------=_Part_0_7369521.1334933184052--