I have a User model which has_many :portfolios and each Portfolio has_many :pictures. My routes look like this: resources :users do resources :portfolios do resources :pictures endend Then I try to create a new Portfolio like this: <%= link_to "new portfolio...", new_user_portfolio_path(current_user) %> With a form like this: <%= form_for [current_user, @portfolio], html: { class: "form_settings" } do |f| %>...<% end %> But when I click on "new portfolio..." my URL says /users/12/portfolios/new and I get this error: No route matches {:action=>"show", :controller=>"portfolios", :user_id=><User id: 12, name: "michael", password_digest: "d787f56b080945c1ec0b3343cbf962ca427bb8ef", remember_token: "dL4nPlt0E5azUMemNIvkdg", admin: false, created_at: "2013-03-03 01:18:19", updated_at: "2013-03-03 19:56:28">, :id=><Portfolio id: nil, user_id: 12, name: nil, created_at: nil, updated_at: nil>} -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/b_jQjXyUg_0J. For more options, visit https://groups.google.com/groups/opt_out.
I have a User model which has_many :portfolios and each Portfolio has_many :pictures. My routes look like this: resources :users do resources :portfolios do resources :pictures end end Then I try to create a new Portfolio like this: <%= link_to "new portfolio...", new_user_portfolio_path(current_user) %> With a form like this: <%= form_for [current_user, @portfolio], html: { class: "form_settings" } do |f| %> ... <% end %> But when I click on "new portfolio..." my URL says /users/12/portfolios/new and I get this error: Routing Error No route matches {:controller=>"pictures", :user_id=>#<User id: 12, name: "michael", password_digest: "d787f56b080945c1ec0b3343cbf962ca427bb8ef", remember_token: "dL4nPlt0E5azUMemNIvkdg", admin: false, created_at: "2013-03-03 01:18:19", updated_at: "2013-03-03 19:56:28">, :portfolio_id=>#<Portfolio id: nil, user_id: 12, name: nil, created_at: nil, updated_at: nil>} -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/08Sdx5-I5EcJ. For more options, visit https://groups.google.com/groups/opt_out.
Is that route in ''rake routes''? Greg Akins http://twitter.com/akinsgre On Mon, Mar 4, 2013 at 11:32 AM, mike <mikeglaz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a User model which has_many :portfolios and each Portfolio has_many > :pictures. My routes look like this: > > resources :users do > resources :portfolios do > resources :pictures > end > end > > Then I try to create a new Portfolio like this: > > <%= link_to "new portfolio...", new_user_portfolio_path(current_user) %> > > With a form like this: > > <%= form_for [current_user, @portfolio], html: { class: "form_settings" } > do |f| %> > ... > <% end %> > > But when I click on "new portfolio..." my URL says > /users/12/portfolios/new and I get this error: > > Routing Error > > No route matches {:controller=>"pictures", :user_id=>#<User id: 12, name: "michael", password_digest: "d787f56b080945c1ec0b3343cbf962ca427bb8ef", remember_token: "dL4nPlt0E5azUMemNIvkdg", admin: false, created_at: "2013-03-03 01:18:19", updated_at: "2013-03-03 19:56:28">, :portfolio_id=>#<Portfolio id: nil, user_id: 12, name: nil, created_at: nil, updated_at: nil>} > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/08Sdx5-I5EcJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Ok, figured out a part of it. My layout file has a toolbar which looks like this: <% current_user.portfolios.each do |portfolio| %> <li><%= link_to portfolio.name, user_portfolio_path(current_user, portfolio) %></li> <% end %> <li><%= link_to "new portfolio...", new_user_portfolio_path(current_user) %></li> Which works when I''m at */users/12* but it breaks when I go to * /users/12/portfolios/new*. So my question is why can''t I link to the *show* page of my portfolios from the *new* page? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/tUGUH_7cLtYJ. For more options, visit https://groups.google.com/groups/opt_out.
yes, I checked all my routes against ''rake routes'' On Monday, March 4, 2013 11:21:10 AM UTC-6, Greg Akins wrote:> > Is that route in ''rake routes''? > > Greg Akins > http://twitter.com/akinsgre > > > > On Mon, Mar 4, 2013 at 11:32 AM, mike <mike...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <javascript:>>wrote: > >> I have a User model which has_many :portfolios and each Portfolio >> has_many :pictures. My routes look like this: >> >> resources :users do >> resources :portfolios do >> resources :pictures >> end >> end >> >> Then I try to create a new Portfolio like this: >> >> <%= link_to "new portfolio...", new_user_portfolio_path(current_user) %> >> >> With a form like this: >> >> <%= form_for [current_user, @portfolio], html: { class: "form_settings" } >> do |f| %> >> ... >> <% end %> >> >> But when I click on "new portfolio..." my URL says >> /users/12/portfolios/new and I get this error: >> >> Routing Error >> >> No route matches {:controller=>"pictures", :user_id=>#<User id: 12, name: "michael", password_digest: "d787f56b080945c1ec0b3343cbf962ca427bb8ef", remember_token: "dL4nPlt0E5azUMemNIvkdg", admin: false, created_at: "2013-03-03 01:18:19", updated_at: "2013-03-03 19:56:28">, :portfolio_id=>#<Portfolio id: nil, user_id: 12, name: nil, created_at: nil, updated_at: nil>} >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-ta...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> To post to this group, send email to rubyonra...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<javascript:> >> . >> To view this discussion on the web visit >> https://groups.google.com/d/msg/rubyonrails-talk/-/08Sdx5-I5EcJ. >> >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/4Lm156keDHoJ. For more options, visit https://groups.google.com/groups/opt_out.
On Monday, March 4, 2013 4:32:10 PM UTC, mike wrote:> I have a User model which has_many :portfolios and each Portfolio has_many :pictures. My routes look like this: > > > > > resources :users do > resources :portfolios do > resources :pictures > end > end > >> Routing Error > No route matches {:controller=>"pictures", :user_id=>#<User id: 12, name: "michael", password_digest: "d787f56b080945c1ec0b3343cbf962ca427bb8ef", remember_token: "dL4nPlt0E5azUMemNIvkdg", admin: false, created_at: "2013-03-03 01:18:19", updated_at: "2013-03-03 19:56:28">, :portfolio_id=>#<Portfolio id: nil, user_id: 12, name: nil, created_at: nil, updated_at: nil>}From this it sounds like somewhere you''re trying to link (or generate a form that posts to) the pictures for an unsaved portfolio. This doesn''t work because te URL for that would have the portfolio id in it, but the portfolio in question doesn''t have an id yet. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/lapDZ0MHj_oJ. For more options, visit https://groups.google.com/groups/opt_out.
You know what, I posted the wrong error. The correct error is this: No route matches {:action=>"show", :controller=>"portfolios", :user_id=> What fixed it is this: link_to portfolio.name, user_portfolio_path(current_user, portfolio) unless portfolio.new_record? the unless portfolio.new_record? part. But I don''t understand why that fixed it? On Monday, March 4, 2013 12:57:54 PM UTC-6, Frederick Cheung wrote:> > On Monday, March 4, 2013 4:32:10 PM UTC, mike wrote: > > I have a User model which has_many :portfolios and each Portfolio > has_many :pictures. My routes look like this: > > > > > > > > > > resources :users do > > resources :portfolios do > > resources :pictures > > end > > end > > > > > > > > Routing Error > > No route matches {:controller=>"pictures", :user_id=>#<User id: 12, > name: "michael", password_digest: > "d787f56b080945c1ec0b3343cbf962ca427bb8ef", remember_token: > "dL4nPlt0E5azUMemNIvkdg", admin: false, created_at: "2013-03-03 01:18:19", > updated_at: "2013-03-03 19:56:28">, :portfolio_id=>#<Portfolio id: nil, > user_id: 12, name: nil, created_at: nil, updated_at: nil>} > > From this it sounds like somewhere you''re trying to link (or generate a > form that posts to) the pictures for an unsaved portfolio. This doesn''t > work because te URL for that would have the portfolio id in it, but the > portfolio in question doesn''t have an id yet. > > Fred-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/sAnqlFBStgwJ. For more options, visit https://groups.google.com/groups/opt_out.