Skip to content
This repository has been archived by the owner on Sep 13, 2017. It is now read-only.

1.0.2 confusing show and index #20

Closed
JohnColvin opened this issue Feb 21, 2012 · 12 comments
Closed

1.0.2 confusing show and index #20

JohnColvin opened this issue Feb 21, 2012 · 12 comments

Comments

@JohnColvin
Copy link

I upgraded to 1.0.2 and an index path of mine (localhost:3000/students) was giving this error:

No route matches {:action=>"show", :controller=>"students"}

I went back to 1.0.1 and it went back to working.

Here's the students section of my routes file:

resources :students, :only => [:show, :index] do
  resources :enrollments,          :only => [:index, :create, :destroy, :new]
  resources :advisorships,         :only => [:index]
  resources :questionnaires,       :only => [:index]
  resources :assessments,          :only => [:index],                                   :path => 'tests',  :as => 'tests'
  resources :test_attempts,        :only => [:create, :new, :destroy],                  :path => 'tests'
  resources :breadth_requirements, :only => [:index, :destroy, :new, :create, :update], :path => 'breadth'
end
@pixeltrix
Copy link

Can you please post the full backtrace - I believe what's happening is that the student_path helper is being called with a nil value for the :id parameter.

@JohnColvin
Copy link
Author

There is no stack trace.

You're correct. I was calling student_path without the :id parameter. I changed it to students_path, as it should be. It's interesting that this used to work.

@Dinuz
Copy link

Dinuz commented Feb 23, 2012

I have the same identical type of issue. This happen with version 1.0.2 and also with 1.0.3, but is not present with the version 1.0.1 (I rolled back to it).

Now seems to me that this problem is present when are called (in link_to for example) the path to edit and new action.

How we can solve this issue? and what really is so different between the version 1.0.1 and the 1.0.2 and 1.0.3??

In my case it's important noting that I am using the id to call the method (edit or new require ID), the only thing that could let me worry can be the fact that I am using nested attributes and models and I am also using a route grouping method as you did JohnColvin...

@JohnColvin
Copy link
Author

Can you share a line or section of code that is causing issues for issue?

In my case, I was abusing path methods. I should have not been using them the way that I was. I corrected them and everything is working for me now.

As far as I can tell, this isn't a bug. They are restricting some usage that should not have been allowed in the first place.

@Dinuz
Copy link

Dinuz commented Feb 23, 2012

I agree, I could share some code too.
I am not abusing the path method, I am sure (in your case you were pointing to index action, that require to have the s at the end of the name eg. profiles_path), in my case I am pointing at edit and new action, and their path don't require the s at the end (eg. new_profile_path and edit_profile_path).

resources :profiles , :module => "members" do (NOTE this is an has_one association for users)
resources :bios (NOTE this is an has_one association for profiles)
resources :livings (NOTE this is an has_many association for profiles)
end

No matter what I do, using the version of journey 1.0.2 or 1.0.3 through an error, and the error is the same of yours:

No route matches {:action=>"show", :controller=>"members/profiles"}

I believe there is an issue with the show action in someway with the new updated version of journey, what it is, is what really would love to understand.

@pixeltrix
Copy link

The error you're getting is indicative of you using the profile_path url helper with no params or a nil param:

>> app.profile_path
ActionController::RoutingError: No route matches {:action=>"show", :controller=>"members/profiles"}

you wouldn't get the error with new_profile_path as it doesn't take any params and edit_profile_path would show the following:

>> app.edit_profile_path
ActionController::RoutingError: No route matches {:action=>"edit", :controller=>"members/profiles"}

If you can, please post the template in a gist so I can have a look.

@Dinuz
Copy link

Dinuz commented Feb 23, 2012

Sorry but what you are pointing out is not what really happen (at least not directly).

I land on the profile show view (user has one profile, and current_user is what pass the id to profile, after log in).
On the profile show page, I have different link_to that are connector for the edit and new action of different models (each of this model is a nested resource to profile model, and someone of this model has a relationship has_one with profile, and other have has_many).

When an user sign up, the app automatically create a record in the user model, a record in profile model, and a record in the nested resources of profile that have an has_one relation with the same profile; the other nested resources (the has_many ones) are not automatically created with the sign up process, but are optionally created later by the user if he/she want.

Obviously this nested resources with has_many relationship are empty (there is no record) at the beginning.

The error happen for this resources, using the new path or the edit path (obviously there is not an id for the nested resources yet, but there is the id of the user and the id of the profile).

an example can be:

ON PROFILE SHOW PAGE:

<% if (@user == current_user) %>

<%= link_to 'Profile Settings', edit_profile_path %>

(NOTE NO GIVE ERROR)

<%= link_to 'Account Settings', edit_user_registration_path %>

(NOTE GIVE ERROR)
<% end %>

<%= link_to profile_path %>

or also on the same page:

<%= link_to "Add a new Living", new_profile_living_path(@Profile) %> (NOTE GIVE ERROR)

The error is always the same:

No route matches {:action=>"show", :controller=>"members/profiles"}

in every case!

@pixeltrix
Copy link

This is where the error is:

<%= link_to profile_path %>

@Dinuz
Copy link

Dinuz commented Feb 23, 2012

Why?!?

Sent from my iPhone

On Feb 23, 2012, at 3:50 AM, Andrew Whitereply@reply.github.com wrote:

This is where the error is:

<%= link_to profile_path %>

Reply to this email directly or view it on GitHub:
#20 (comment)

@pixeltrix
Copy link

You have the following routes:

resources :profiles, :module => "members" do
  resources :bios
  resources :livings
end

This gives the following routes:

     profiles_index GET    /profiles/index(.:format)                        profiles#index
       profile_bios GET    /profiles/:profile_id/bios(.:format)             members/bios#index
                    POST   /profiles/:profile_id/bios(.:format)             members/bios#create
    new_profile_bio GET    /profiles/:profile_id/bios/new(.:format)         members/bios#new
   edit_profile_bio GET    /profiles/:profile_id/bios/:id/edit(.:format)    members/bios#edit
        profile_bio GET    /profiles/:profile_id/bios/:id(.:format)         members/bios#show
                    PUT    /profiles/:profile_id/bios/:id(.:format)         members/bios#update
                    DELETE /profiles/:profile_id/bios/:id(.:format)         members/bios#destroy
    profile_livings GET    /profiles/:profile_id/livings(.:format)          members/livings#index
                    POST   /profiles/:profile_id/livings(.:format)          members/livings#create
 new_profile_living GET    /profiles/:profile_id/livings/new(.:format)      members/livings#new
edit_profile_living GET    /profiles/:profile_id/livings/:id/edit(.:format) members/livings#edit
     profile_living GET    /profiles/:profile_id/livings/:id(.:format)      members/livings#show
                    PUT    /profiles/:profile_id/livings/:id(.:format)      members/livings#update
                    DELETE /profiles/:profile_id/livings/:id(.:format)      members/livings#destroy
           profiles GET    /profiles(.:format)                              members/profiles#index
                    POST   /profiles(.:format)                              members/profiles#create
        new_profile GET    /profiles/new(.:format)                          members/profiles#new
       edit_profile GET    /profiles/:id/edit(.:format)                     members/profiles#edit
            profile GET    /profiles/:id(.:format)                          members/profiles#show
                    PUT    /profiles/:id(.:format)                          members/profiles#update
                    DELETE /profiles/:id(.:format)                          members/profiles#destroy

Specifically this route:

            profile GET    /profiles/:id(.:format)                          members/profiles#show

Therefore you need to give profile_path a valid :id parameter (i.e. not nil or false), e.g:

<%= link_to profile_path(@user) %>

@Dinuz
Copy link

Dinuz commented Feb 23, 2012

@pixeltrix Ok You were super right....

I found the issue, was related with the <%= link_to profile_path %>, but was not in the code that I showed you before.

Was a link in the header (I am actually using a partial for that), that was <%= link_to profile_path %> and this obviously couldn't work for the has_many association because nothing was created before, and then there was an id nil. This instead was working for the has_one association, I believe for the simple reason that this association were created with the user, and then they presented the same id of the user (probably if in the database I modify the id, and put different from the user, the code will throw the same error).

I fixed the issue not using <%= link_to profile_path(@user) %> (because still this give an error), but using instead <%= link_to profile_path(current_user) %>

Now everything works fine also with 1.0.3 !!!

Apologize, but I have had the opportunity to look inside of the code just few minutes ago.

Thanks again, for pointing me in the right direction.

Anyway, I'd like to understand what changed between the version 1.0.1 and the 1.0.2 and 1.0.3....This was allowed before, then I deduct that was a bug in the older version?

@pixeltrix
Copy link

@Dinuz yes it was a bug - nil parameters were being converted to empty strings.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants