routes

40 views
Skip to first unread message

Joe Guerra

unread,
Sep 11, 2017, 1:05:12 PM9/11/17
to Ruby on Rails: Talk
I believe I messed up the routes in one of my models.  

Should I delete the model and try again?  


Thanks,
Joe

Norbert Melzer

unread,
Sep 11, 2017, 1:08:52 PM9/11/17
to Ruby on Rails: Talk

Routes do not belong to a model, they map request pathes to actions in controllers, so can you please go into a little bit more detail?


--
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...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8797c104-ccef-4b5d-ac5c-cf5b1ae0c2ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Edwards

unread,
Sep 11, 2017, 1:16:01 PM9/11/17
to Ruby on Rails: Talk
As Nobert says they are independent.  Post your routes.rb, where the view is you want the route to go to and say what you were expecting. 

http://guides.rubyonrails.org/v3.1.3/routing.html may help.

Also if you have not done so do the Getting started guide on the rails website.  See it through to the end.  I got confused half way when I did it but kept with it and its a great foundation.

I myself have a habit of just diving in and doing stuff. Knowing the conventions rails has and the rails way saves a lot of time in the medium term.

Ben

Hassan Schroeder

unread,
Sep 11, 2017, 1:33:09 PM9/11/17
to rubyonrails-talk
On Mon, Sep 11, 2017 at 10:16 AM, Ben Edwards <lo...@funkytwig.com> wrote:

> http://guides.rubyonrails.org/v3.1.3/routing.html may help.

Uh, any particular reason to post a link to a guide for a version of
Rails that's been unsupported for a very long time?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Ben Edwards

unread,
Sep 11, 2017, 1:43:32 PM9/11/17
to Ruby on Rails: Talk
Ineptitude;): 

Should be http://guides.rubyonrails.org/routing.html.

Ben

Joe Guerra

unread,
Sep 11, 2017, 9:15:42 PM9/11/17
to Ruby on Rails: Talk
ok, it looks like my other form


<%= simple_form_for @gallery do |f| %>
<% if @gallery.errors.any? %>
<div id="error_explanation">
<h2>
<%= "#{pluralize(@gallery.errors.count, "error")} prohibited this image from being saved:" %>
</h2>
<ul>
<% @gallerys.errors.full_messages.each do |msg| %>
<li>
<%= msg %>
</li>
<% end %>
</ul>
</div>
<% end %>


this is the error i'm getting...

NoMethodError in Gallery#new

Showing /Users/joeguerra/RubymineProjects/portfolio/app/views/gallery/_form.html.erb where line #12 raised:

undefined method `galleries_path' for #<#<Class:0x007feecb78ac50>:0x007feec7571aa8>
Did you mean?  gallery_path
Extracted source (around line #12):
10
11
12
13
14
15
              
</style>
<%= simple_form_for @gallery do |f| %>
<% if @gallery.errors.any? %>
<div id="error_explanation">
<h2>

Trace of template inclusion: app/views/gallery/new.html.erb



I'm using... in my routes file.

get resources :gallery


Thanks,
Joe

Norbert Melzer

unread,
Sep 12, 2017, 3:45:29 AM9/12/17
to rubyonra...@googlegroups.com
Am 12.09.2017 um 03:15 schrieb Joe Guerra:
> get resources :gallery
You do have this in your routesfile literally? Seems invalid for me.

Also As far as I can remember the convention, `resources` needs the
plural name, not the singular name. But I haven't used rails since about
3.x-ish.

signature.asc

Joe Guerra

unread,
Sep 12, 2017, 10:15:07 AM9/12/17
to Ruby on Rails: Talk
RIght, I tried resources galleries, resources gallerys

But all come up with other errors.  My post controller and views work, this gallery controller seems to look the same?  (I don't get it).

Thanks,
Joe

Joe Guerra

unread,
Sep 12, 2017, 10:21:12 AM9/12/17
to Ruby on Rails: Talk
Doesn't running the scaffold command put the route in the routes file for you?

Colin Law

unread,
Sep 12, 2017, 10:23:21 AM9/12/17
to Ruby on Rails: Talk
On 12 September 2017 at 15:15, Joe Guerra <JGu...@jginfosys.com> wrote:
> RIght, I tried resources galleries, resources gallerys
>
> But all come up with other errors. My post controller and views work, this
> gallery controller seems to look the same? (I don't get it).

rails routes
will show you all configured routes, which may help

Colin

>
> Thanks,
> Joe
>
> On Tuesday, September 12, 2017 at 3:45:29 AM UTC-4, Norbert Melzer wrote:
>>
>> Am 12.09.2017 um 03:15 schrieb Joe Guerra:
>> > get resources :gallery
>> You do have this in your routesfile literally? Seems invalid for me.
>>
>> Also As far as I can remember the convention, `resources` needs the
>> plural name, not the singular name. But I haven't used rails since about
>> 3.x-ish.
>>
> --
> 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...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/7846a77e-4bb0-42d0-aab8-f087843a30b2%40googlegroups.com.

Joe Guerra

unread,
Sep 12, 2017, 11:24:25 AM9/12/17
to rubyonra...@googlegroups.com
yes, I know that.   :)

On Tue, Sep 12, 2017 at 10:21 AM, Colin Law <cla...@gmail.com> wrote:
On 12 September 2017 at 15:15, Joe Guerra <JGu...@jginfosys.com> wrote:
> RIght, I tried resources galleries, resources gallerys
>
> But all come up with other errors.  My post controller and views work, this
> gallery controller seems to look the same?  (I don't get it).

rails routes
will show you all configured routes, which may help

Colin

>
> Thanks,
> Joe
>
> On Tuesday, September 12, 2017 at 3:45:29 AM UTC-4, Norbert Melzer wrote:
>>
>> Am 12.09.2017 um 03:15 schrieb Joe Guerra:
>> > get resources :gallery
>> You do have this in your routesfile literally? Seems invalid for me.
>>
>> Also As far as I can remember the convention, `resources` needs the
>> plural name, not the singular name. But I haven't used rails since about
>> 3.x-ish.
>>
> --
> 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@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
--
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsF-rFqJpw_EOcrjsmpjCsPWO3WfvmGq71mA35b9_e4Yw%40mail.gmail.com.

Norbert Melzer

unread,
Sep 12, 2017, 11:26:00 AM9/12/17
to rubyonra...@googlegroups.com
On 09/12/2017 05:22 PM, Joe Guerra wrote:
> On Tue, Sep 12, 2017 at 10:21 AM, Colin Law <cla...@gmail.com
> <mailto:cla...@gmail.com>> wrote:
>
> rails routes
> will show you all configured routes, which may help
>
> yes, I know that.   :)


But you did not understand… If you had shown the output, it might be
easier for us to see what exactly went wrong.

signature.asc

Ben Edwards

unread,
Sep 12, 2017, 4:26:01 PM9/12/17
to Ruby on Rails: Talk
+1

post output from '$ rails routes', it will really help people  help you.

also 'NoMethodError in Gallery#new sounds like the new method is missing from the Gallery controller so posting that would also be good.

Ben

Joe Guerra

unread,
Sep 12, 2017, 4:29:49 PM9/12/17
to rubyonra...@googlegroups.com
Thanks, I'll add the post the results of my routes tonight. (when I'm at home).

To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/90a4bc9f-950c-4ac0-8234-17cb58da2371%40googlegroups.com.

Colin Law

unread,
Sep 12, 2017, 5:03:56 PM9/12/17
to Ruby on Rails: Talk
On 12 September 2017 at 02:15, Joe Guerra <JGu...@jginfosys.com> wrote:
> ...
> I'm using... in my routes file.
>
> get resources :gallery

Why is the 'get' there?

Colin

Joe Guerra

unread,
Sep 12, 2017, 5:29:34 PM9/12/17
to Ruby on Rails: Talk
here's the output of my routes... (sorry about the formatting)

                Prefix Verb   URI Pattern                     Controller#Action
                 androids GET    /androids(.:format)             androids#index
                          POST   /androids(.:format)             androids#create
              new_android GET    /androids/new(.:format)         androids#new
             edit_android GET    /androids/:id/edit(.:format)    androids#edit
                  android GET    /androids/:id(.:format)         androids#show
                          PATCH  /androids/:id(.:format)         androids#update
                          PUT    /androids/:id(.:format)         androids#update
                          DELETE /androids/:id(.:format)         androids#destroy
        new_admin_session GET    /admins/sign_in(.:format)       devise/sessions#new
            admin_session POST   /admins/sign_in(.:format)       devise/sessions#create
    destroy_admin_session DELETE /admins/sign_out(.:format)      devise/sessions#destroy
       new_admin_password GET    /admins/password/new(.:format)  devise/passwords#new
      edit_admin_password GET    /admins/password/edit(.:format) devise/passwords#edit
           admin_password PATCH  /admins/password(.:format)      devise/passwords#update
                          PUT    /admins/password(.:format)      devise/passwords#update
                          POST   /admins/password(.:format)      devise/passwords#create
cancel_admin_registration GET    /admins/cancel(.:format)        devise/registrations#cancel
   new_admin_registration GET    /admins/sign_up(.:format)       devise/registrations#new
  edit_admin_registration GET    /admins/edit(.:format)          devise/registrations#edit
       admin_registration PATCH  /admins(.:format)               devise/registrations#update
                          PUT    /admins(.:format)               devise/registrations#update
                          DELETE /admins(.:format)               devise/registrations#destroy
                          POST   /admins(.:format)               devise/registrations#create
                 ckeditor        /ckeditor                       Ckeditor::Engine
                     root GET    /                               posts#index
                    posts GET    /posts(.:format)                posts#index
                          POST   /posts(.:format)                posts#create
                 new_post GET    /posts/new(.:format)            posts#new
                edit_post GET    /posts/:id/edit(.:format)       posts#edit
                     post GET    /posts/:id(.:format)            posts#show
                          PATCH  /posts/:id(.:format)            posts#update
                          PUT    /posts/:id(.:format)            posts#update
                          DELETE /posts/:id(.:format)            posts#destroy
            gallery_index GET    /gallery(.:format)              gallery#index
                          POST   /gallery(.:format)              gallery#create
              new_gallery GET    /gallery/new(.:format)          gallery#new
             edit_gallery GET    /gallery/:id/edit(.:format)     gallery#edit
                  gallery GET    /gallery/:id(.:format)          gallery#show
                          PATCH  /gallery/:id(.:format)          gallery#update
                          PUT    /gallery/:id(.:format)          gallery#update
                          DELETE /gallery/:id(.:format)          gallery#destroy
            android_index GET    /android(.:format)              android#index
                          POST   /android(.:format)              android#create
                          GET    /android/new(.:format)          android#new
                          GET    /android/:id/edit(.:format)     android#edit
                          GET    /android/:id(.:format)          android#show
                          PATCH  /android/:id(.:format)          android#update
                          PUT    /android/:id(.:format)          android#update
                          DELETE /android/:id(.:format)          android#destroy

Routes for Ckeditor::Engine:
        pictures GET    /pictures(.:format)             ckeditor/pictures#index
                 POST   /pictures(.:format)             ckeditor/pictures#create
         picture DELETE /pictures/:id(.:format)         ckeditor/pictures#destroy
attachment_files GET    /attachment_files(.:format)     ckeditor/attachment_files#index
                 POST   /attachment_files(.:format)     ckeditor/attachment_files#create
 attachment_file DELETE /attachment_files/:id(.:format) ckeditor/attachment_files#destroy

Norbert Melzer

unread,
Sep 12, 2017, 5:46:00 PM9/12/17
to rubyonra...@googlegroups.com
I asked before, but that wasn't heard, perhaps increasing the noise
might help?

signature.asc

Rob Biedenharn

unread,
Sep 12, 2017, 7:11:20 PM9/12/17
to rubyonra...@googlegroups.com
I'm removing most of the "noise" from your output and focussing on the gallery-relevant bits:

On 2017-Sep-12, at 17:29 , Joe Guerra <JGu...@jginfosys.com> wrote:

here's the output of my routes... (sorry about the formatting)

                Prefix Verb   URI Pattern                     Controller#Action
            gallery_index GET    /gallery(.:format)              gallery#index
                          POST   /gallery(.:format)              gallery#create
              new_gallery GET    /gallery/new(.:format)          gallery#new
             edit_gallery GET    /gallery/:id/edit(.:format)     gallery#edit
                  gallery GET    /gallery/:id(.:format)          gallery#show
                          PATCH  /gallery/:id(.:format)          gallery#update
                          PUT    /gallery/:id(.:format)          gallery#update
                          DELETE /gallery/:id(.:format)          gallery#destroy

the key bit to notice is that the index route is "named" gallery_index because you used:

    resources :gallery

and :gallery is the singular form

You very likely want to say instead:

    resources :galleries

which will give you similar routes *except* from the index:

[ruby-2.4.1p111] //tmp $ cd example/
[ruby-2.4.1p111] tmp/example (master #%) $ rails g resources Gallery
Running via Spring preloader in process 61722
Could not find generator 'resources'. Maybe you meant 'resource', 'resource_route' or 'assets'
Run `rails generate --help` for more options.
[ruby-2.4.1p111] tmp/example (master #%) $ rails g resource Gallery
Running via Spring preloader in process 61823
      invoke  active_record
      create    db/migrate/20170912230824_create_galleries.rb
      create    app/models/gallery.rb
      invoke    test_unit
      create      test/models/gallery_test.rb
      create      test/fixtures/galleries.yml
      invoke  controller
      create    app/controllers/galleries_controller.rb
      invoke    erb
      create      app/views/galleries
      invoke    test_unit
      create      test/controllers/galleries_controller_test.rb
      invoke    helper
      create      app/helpers/galleries_helper.rb
      invoke      test_unit
      invoke    assets
      invoke      coffee
      create        app/assets/javascripts/galleries.coffee
      invoke      scss
      create        app/assets/stylesheets/galleries.scss
      invoke  resource_route
       route    resources :galleries
[ruby-2.4.1p111] tmp/example (master #%) $ cat config/routes.rb 
Rails.application.routes.draw do
  resources :galleries
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end
[ruby-2.4.1p111] tmp/example (master #%) $ rails routes
      Prefix Verb   URI Pattern                   Controller#Action
   galleries GET    /galleries(.:format)          galleries#index
             POST   /galleries(.:format)          galleries#create
 new_gallery GET    /galleries/new(.:format)      galleries#new
edit_gallery GET    /galleries/:id/edit(.:format) galleries#edit
     gallery GET    /galleries/:id(.:format)      galleries#show
             PATCH  /galleries/:id(.:format)      galleries#update
             PUT    /galleries/:id(.:format)      galleries#update
             DELETE /galleries/:id(.:format)      galleries#destroy


Note the routes for index, create, and new ^^

-Rob


On Tuesday, September 12, 2017 at 5:03:56 PM UTC-4, Colin Law wrote:
On 12 September 2017 at 02:15, Joe Guerra <JGu...@jginfosys.com> wrote:
> ...
> I'm using... in my routes file.
>
> get resources :gallery

Why is the 'get' there?

Colin

--
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...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

Joe Guerra

unread,
Sep 13, 2017, 8:03:33 PM9/13/17
to rubyonra...@googlegroups.com
Thanks.  What should I do to fix it?  Should I re-run the generator?



To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.

--
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@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9D2B37D1-18F3-4FC0-9E65-31E73C9DB0D1%40gmail.com.

Colin Law

unread,
Sep 14, 2017, 3:31:38 AM9/14/17
to Ruby on Rails: Talk
On 14 September 2017 at 01:02, Joe Guerra <jgu...@jginfosys.com> wrote:
Thanks.  What should I do to fix it?  Should I re-run the generator?

You could start by trying Rob's suggestion.

Colin
 

Joe Guerra

unread,
Sep 15, 2017, 5:49:42 PM9/15/17
to Ruby on Rails: Talk
Ok, I see where I made my error.  

I refactored the names of a few things and it's working much better now.




To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

--
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...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.

--
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...@googlegroups.com.
To post to this group, send email to rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages