Hello. I am a beginner. I wanna make a route like this: /document-:language-:month-:year.pdf With 3 params, so I can retrieve a PDF in a URL like: /document-english-june-2008.pdf I have 2 problems... 1. It seems I can''t put more than 1 param between the slashes The route /document/:language/:month/:year.pdf works fine. Because I have each params isolated... 2. It seems that the "-" cannot be used in the route. Is it true? Is there a workaround? Thanks
On Sun, Nov 15, 2009 at 7:24 PM, Wagner <wagner-/RfkG1aXhJ1BDgjK7y7TUQ@public.gmane.org> wrote:> > Hello. I am a beginner. > I wanna make a route like this: > > /document-:language-:month-:year.pdf > > With 3 params, so I can retrieve a PDF in a URL like: > > /document-english-june-2008.pdf > > I have 2 problems... > > 1. It seems I can''t put more than 1 param between the slashes > The route /document/:language/:month/:year.pdf works fine. Because I > have each params isolated... > > 2. It seems that the "-" cannot be used in the route. Is it true? Is > there a workaround?I think so. You can come close url /document/english-june-2008.pdf route /document/:permalink then in the controller parse the single permalink parameter however you wish. I used the name permalink since this is a general term for a human readable ''id''. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale
if the only thing you need is a nicer url you can override the to_params method in the model. something like: def to_params "#{id}-#{language}-#{year}-#{month}" end
I tried this. It works but only with underscores, but it doesn''t work with "-". On Nov 16, 12:22 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Nov 15, 2009 at 7:24 PM, Wagner <wag...-/RfkG1aXhJ1BDgjK7y7TUQ@public.gmane.org> wrote: > > > Hello. I am a beginner. > > I wanna make a route like this: > > > /document-:language-:month-:year.pdf > > > With 3 params, so I can retrieve a PDF in a URL like: > > > /document-english-june-2008.pdf > > > I have 2 problems... > > > 1. It seems I can''t put more than 1 param between the slashes > > The route /document/:language/:month/:year.pdf works fine. Because I > > have each params isolated... > > > 2. It seems that the "-" cannot be used in the route. Is it true? Is > > there a workaround? > > I think so. > > You can come close > > url /document/english-june-2008.pdf > route /document/:permalink > > then in the controller parse the single permalink parameter however you wish. > > I used the name permalink since this is a general term for a human > readable ''id''. > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale
it should, i used something like that (i mean with ''-'') did you keep the numeric id at the beginning of the to_params? you can search for Document.find(params[:id]) at usual because params [:id] is passed through to_i "43-en-2008-04.pdf".to_i == 43 On 16 Nov, 21:08, Wagner <wag...-/RfkG1aXhJ1BDgjK7y7TUQ@public.gmane.org> wrote:> I tried this. It works but only with underscores, but it doesn''t work > with "-". > > On Nov 16, 12:22 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Sun, Nov 15, 2009 at 7:24 PM, Wagner <wag...-/RfkG1aXhJ1BDgjK7y7TUQ@public.gmane.org> wrote: > > > > Hello. I am a beginner. > > > I wanna make a route like this: > > > > /document-:language-:month-:year.pdf > > > > With 3 params, so I can retrieve a PDF in a URL like: > > > > /document-english-june-2008.pdf > > > > I have 2 problems... > > > > 1. It seems I can''t put more than 1 param between the slashes > > > The route /document/:language/:month/:year.pdf works fine. Because I > > > have each params isolated... > > > > 2. It seems that the "-" cannot be used in the route. Is it true? Is > > > there a workaround? > > > I think so. > > > You can come close > > > url /document/english-june-2008.pdf > > route /document/:permalink > > > then in the controller parse the single permalink parameter however you wish. > > > I used the name permalink since this is a general term for a human > > readable ''id''. > > > -- > > Rick DeNatale > > > Blog:http://talklikeaduck.denhaven2.com/ > > Twitter:http://twitter.com/RickDeNatale > > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > > LinkedIn:http://www.linkedin.com/in/rickdenatale
You can try friendly_id http://github.com/norman/friendly_id On Nov 16, 8:24 am, Wagner <wag...-/RfkG1aXhJ1BDgjK7y7TUQ@public.gmane.org> wrote:> Hello. I am a beginner. > I wanna make a route like this: > > /document-:language-:month-:year.pdf > > With 3 params, so I can retrieve a PDF in a URL like: > > /document-english-june-2008.pdf > > I have 2 problems... > > 1. It seems I can''t put more than 1 param between the slashes > The route /document/:language/:month/:year.pdf works fine. Because I > have each params isolated... > > 2. It seems that the "-" cannot be used in the route. Is it true? Is > there a workaround? > > Thanks