Rafael
2007-Jun-17 15:29 UTC
One App, two REST questions - Nested Ressources, meaningful URLs
Hi everybody,
Thank you for reading this, may you can help me out here, because I
looked at many ressources and didn''t find a solution yet.
Thank you very much
regards
Rafael
First question
--------------------
I have a two model app: vacancy, candidacy
- vacancy has many candidacies
- candidacy belongs to vacancy
How can I access a ressource directly, even if its a nested ressource?
How can I manage this, that creating a new candidacy can be done
without having a relation to a vacancy, so that having a vacancy isn''t
mandatory?
A cancidacy could be applied in relation to an existing vacancy or a
spontanous application, and how should then the REST ressources look
like, is there a DRY way to do it or do I actually have to create two
different forms?
What is working is this:
vacancies/10200-31/candidacies/new
but not
candidacies/new
I got this error:
ActionView::TemplateError (candidacies_url failed to generate from
{:action=>"index", :controller=>"candidacies"} - you
may have
ambiguous routes, or you may need to supply additional parameters for
this route. content_url has the following required parameters:
["vacancies", :vacancy_id, "candidacies"] - are they all
satisifed?)
on line #6 of app/views/candidacies/new.rhtml:
3: <%= error_messages_for :candidacy %>
4:
5:
6: <% form_for(:candidacy, :url => candidacies_path(), :html =>
{ :method => :post, :multipart => true}) do |f| %>
7:
8: <%
9:
Second question
-------------------------
Is this the right way for meaningful URLs?
vacancy_path(vacancy.vacancy_number) =>>> vacancies/10200-31
and in the show action
def show
@vacancy = Vacancy.find_by_vacancy_number(params[:id])
end
Is this a good way to do it? Or do I have to make other settings in
the routes.rb, so that the app knows, which attribute is gonna be
submitted? (The attribute params[:vacancy_number] is used though)
My routes.rb looks like this
First, this is my routes.rb
map.resources :vacancies do |vacancy|
vacancy.resources :candidacies
end
map.connect '':controller/service.wsdl'', :action =>
''wsdl''
# Install the default route as the lowest priority.
map.connect '':controller/:action/:id.:format''
map.connect '':controller/:action/:id''
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
-~----------~----~----~----~------~----~------~--~---
Rick Olson
2007-Jun-17 17:18 UTC
Re: One App, two REST questions - Nested Ressources, meaningful URLs
On 6/17/07, Rafael <beyoumedia-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi everybody, > > Thank you for reading this, may you can help me out here, because I > looked at many ressources and didn''t find a solution yet. > > Thank you very much > > regards > > Rafael > > > > First question > -------------------- > > > I have a two model app: vacancy, candidacy > > - vacancy has many candidacies > - candidacy belongs to vacancy > > > How can I access a ressource directly, even if its a nested ressource?Create a second route for it. Things behave a bit differently in edge rails (rails 2.0) so it might help to prepare now: OLD: map.resources :vacancies do |v| v.resources :candidacies # candidacies_url end NEW: map.resources :vacancies do |v| v.resources :candidacies # vanancy_candidacies_url end map.resources :candidacies # candidacies_url Edge rails adds the parent name prefix to the nested routes. This way you can have both without having clashing routes. Perhaps you should use the :name_prefix option now.> Second question > ------------------------- > > Is this the right way for meaningful URLs? > > > vacancy_path(vacancy.vacancy_number) =>>> vacancies/10200-31 > > and in the show action > > def show > @vacancy = Vacancy.find_by_vacancy_number(params[:id]) > endYup. Routes don''t care what db attribute is pulled. -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rafael
2007-Jun-17 19:27 UTC
Re: One App, two REST questions - Nested Ressources, meaningful URLs
Thank you very much, lets have a try :-) On 17 Jun., 19:18, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6/17/07, Rafael <beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > Hi everybody, > > > Thank you for reading this, may you can help me out here, because I > > looked at many ressources and didn''t find a solution yet. > > > Thank you very much > > > regards > > > Rafael > > > First question > > -------------------- > > > I have a two model app: vacancy, candidacy > > > - vacancy has many candidacies > > - candidacy belongs to vacancy > > > How can I access a ressource directly, even if its a nested ressource? > > Create a second route for it. Things behave a bit differently in edge > rails (rails 2.0) so it might help to prepare now: > > OLD: > map.resources :vacancies do |v| > v.resources :candidacies # candidacies_url > end > > NEW: > map.resources :vacancies do |v| > v.resources :candidacies # vanancy_candidacies_url > end > map.resources :candidacies # candidacies_url > > Edge rails adds the parent name prefix to the nested routes. This way > you can have both without having clashing routes. Perhaps you should > use the :name_prefix option now. > > > Second question > > ------------------------- > > > Is this the right way for meaningful URLs? > > > vacancy_path(vacancy.vacancy_number) =>>> vacancies/10200-31 > > > and in the show action > > > def show > > @vacancy = Vacancy.find_by_vacancy_number(params[:id]) > > end > > Yup. Routes don''t care what db attribute is pulled. > > -- > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rafael
2007-Jun-18 13:49 UTC
Re: One App, two REST questions - Nested Ressources, meaningful URLs
Thanks Rick,
Unfotunately I get always the same error, as before:
Routing Error
no route found to match "/candicacies/new" with {:method=>:get}
may you have a hint
On 17 Jun., 21:27, Rafael
<beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Thank you very much, lets have a try :-)
>
> On 17 Jun., 19:18, "Rick Olson"
<technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > On 6/17/07, Rafael
<beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > Hi everybody,
>
> > > Thank you for reading this, may you can help me out here, because
I
> > > looked at many ressources and didn''t find a solution
yet.
>
> > > Thank you very much
>
> > > regards
>
> > > Rafael
>
> > > First question
> > > --------------------
>
> > > I have a two model app: vacancy, candidacy
>
> > > - vacancy has many candidacies
> > > - candidacy belongs to vacancy
>
> > > How can I access a ressource directly, even if its a nested
ressource?
>
> > Create a second route for it. Things behave a bit differently in edge
> > rails (rails 2.0) so it might help to prepare now:
>
> > OLD:
> > map.resources :vacancies do |v|
> > v.resources :candidacies # candidacies_url
> > end
>
> > NEW:
> > map.resources :vacancies do |v|
> > v.resources :candidacies # vanancy_candidacies_url
> > end
> > map.resources :candidacies # candidacies_url
>
> > Edge rails adds the parent name prefix to the nested routes. This way
> > you can have both without having clashing routes. Perhaps you should
> > use the :name_prefix option now.
>
> > > Second question
> > > -------------------------
>
> > > Is this the right way for meaningful URLs?
>
> > > vacancy_path(vacancy.vacancy_number) =>>>
vacancies/10200-31
>
> > > and in the show action
>
> > > def show
> > > @vacancy = Vacancy.find_by_vacancy_number(params[:id])
> > > end
>
> > Yup. Routes don''t care what db attribute is pulled.
>
> > --
> > Rick
Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Brian Dainton
2007-Jun-18 14:37 UTC
Re: One App, two REST questions - Nested Ressources, meaningful URLs
It''s a spelling error, likely in your link_to call. You have ''candicacies'', not ''candidacies''. - BD On Jun 18, 8:49 am, Rafael <beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks Rick, > > Unfotunately I get always the same error, as before: > > Routing Error > no route found to match "/candicacies/new" with {:method=>:get} > > may you have a hint > > On 17 Jun., 21:27, Rafael <beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thank you very much, lets have a try :-) > > > On 17 Jun., 19:18, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > On 6/17/07, Rafael <beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi everybody, > > > > > Thank you for reading this, may you can help me out here, because I > > > > looked at many ressources and didn''t find a solution yet. > > > > > Thank you very much > > > > > regards > > > > > Rafael > > > > > First question > > > > -------------------- > > > > > I have a two model app: vacancy, candidacy > > > > > - vacancy has many candidacies > > > > - candidacy belongs to vacancy > > > > > How can I access a ressource directly, even if its a nested ressource? > > > > Create a second route for it. Things behave a bit differently in edge > > > rails (rails 2.0) so it might help to prepare now: > > > > OLD: > > > map.resources :vacancies do |v| > > > v.resources :candidacies # candidacies_url > > > end > > > > NEW: > > > map.resources :vacancies do |v| > > > v.resources :candidacies # vanancy_candidacies_url > > > end > > > map.resources :candidacies # candidacies_url > > > > Edge rails adds the parent name prefix to the nested routes. This way > > > you can have both without having clashing routes. Perhaps you should > > > use the :name_prefix option now. > > > > > Second question > > > > ------------------------- > > > > > Is this the right way for meaningful URLs? > > > > > vacancy_path(vacancy.vacancy_number) =>>> vacancies/10200-31 > > > > > and in the show action > > > > > def show > > > > @vacancy = Vacancy.find_by_vacancy_number(params[:id]) > > > > end > > > > Yup. Routes don''t care what db attribute is pulled. > > > > -- > > > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rafael
2007-Jun-18 14:53 UTC
Re: One App, two REST questions - Nested Ressources, meaningful URLs
aahhh ;-( thanks! what a painful post :-D))
now it works, but next issue comes up,... you might know why...
why a normal link_to_remote doesn''t work anymore?
<%= link_to_remote("Delete My Search Profile", :url => {:action
=> :reset_searchcriteria}) %>
ActionController::RoutingError in Vacancies#index
Showing app/views/vacancies/list.rhtml where line #7 raised:
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/routing.rb:1266:in `generate'': No route matches
{:action=>"reset_searchcriteria"}
I get the same Error, when I try with a member route
map.resource :vacancies, :member => {:reset_searchcriteria => :get}
Any clue?
Thank you very much!
greetinx
Rafael
On 18 Jun., 16:37, Brian Dainton
<brian.dain...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> It''s a spelling error, likely in your link_to call. You have
> ''candicacies'', not ''candidacies''.
>
> - BD
>
> On Jun 18, 8:49 am, Rafael
<beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Thanks Rick,
>
> > Unfotunately I get always the same error, as before:
>
> > Routing Error
> > no route found to match "/candicacies/new" with
{:method=>:get}
>
> > may you have a hint
>
> > On 17 Jun., 21:27, Rafael
<beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > Thank you very much, lets have a try :-)
>
> > > On 17 Jun., 19:18, "Rick Olson"
<technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > On 6/17/07, Rafael
<beyoume...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > > Hi everybody,
>
> > > > > Thank you for reading this, may you can help me out
here, because I
> > > > > looked at many ressources and didn''t find a
solution yet.
>
> > > > > Thank you very much
>
> > > > > regards
>
> > > > > Rafael
>
> > > > > First question
> > > > > --------------------
>
> > > > > I have a two model app: vacancy, candidacy
>
> > > > > - vacancy has many candidacies
> > > > > - candidacy belongs to vacancy
>
> > > > > How can I access a ressource directly, even if its a
nested ressource?
>
> > > > Create a second route for it. Things behave a bit
differently in edge
> > > > rails (rails 2.0) so it might help to prepare now:
>
> > > > OLD:
> > > > map.resources :vacancies do |v|
> > > > v.resources :candidacies # candidacies_url
> > > > end
>
> > > > NEW:
> > > > map.resources :vacancies do |v|
> > > > v.resources :candidacies # vanancy_candidacies_url
> > > > end
> > > > map.resources :candidacies # candidacies_url
>
> > > > Edge rails adds the parent name prefix to the nested routes.
This way
> > > > you can have both without having clashing routes. Perhaps
you should
> > > > use the :name_prefix option now.
>
> > > > > Second question
> > > > > -------------------------
>
> > > > > Is this the right way for meaningful URLs?
>
> > > > > vacancy_path(vacancy.vacancy_number) =>>>
vacancies/10200-31
>
> > > > > and in the show action
>
> > > > > def show
> > > > > @vacancy =
Vacancy.find_by_vacancy_number(params[:id])
> > > > > end
>
> > > > Yup. Routes don''t care what db attribute is
pulled.
>
> > > > --
> > > > Rick
Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---