I’m trying to get my feet wet with a simple user registration form.
Username, password, and email. I went through the motions of creating
a static scaffold (well there are no dynamic scaffolds in 2.0,
right?). In doing so, Rails created a members_controller, model, and
all the views.
My thinking was to basically mimic the “new.html.erb” by creating a
register.html.erb and duplicate the code. Then I went to the
members_controller and added a register method that was a carbon copy
of the “new” method. But when I navigate over to http://localhost:3000/members/register
I get the following error:
ActiveRecord::RecordNotFound in MembersController#show
Couldn’t find Member with ID=register
I’m a little confused why it’s barking at the method “show”. Can
someone help clear this up for me? Thanks.
The second one is really good, I really recommend it. She has other
articles, too.
Good Luck,
Jeff M.
longint wrote:
(Mac OS X 10.51, Rails 2.0.2)
I’m trying to get my feet wet with a simple user registration form.
Username, password, and email. I went through the motions of creating
a static scaffold (well there are no dynamic scaffolds in 2.0,
right?). In doing so, Rails created a members_controller, model, and
all the views.
My thinking was to basically mimic the “new.html.erb” by creating a
register.html.erb and duplicate the code. Then I went to the
members_controller and added a register method that was a carbon copy
of the “new” method. But when I navigate over to http://localhost:3000/members/register
I get the following error:
ActiveRecord::RecordNotFound in MembersController#show
Couldn’t find Member with ID=register
I’m a little confused why it’s barking at the method “show”. Can
someone help clear this up for me? Thanks.
Now when I run a scaffold and hit the new link I’ll get: http://localhost:3000/members/new. So I would think that by creating
a “register” view and a “register” method in the members controller,
that register would work the same??
Now when I run a scaffold and hit the new link I’ll get: http://localhost:3000/members/new. So I would think that by creating
a “register” view and a “register” method in the members controller,
that register would work the same??
Nice find K.R. I listened to about half of it… I wasn’t aware that
it was actually a convention to stick to new/edit/etc (although
you can customize it). Ok, I don’t feel so bad now.
I’m not a rails guru by any stretch, but I’ll take a shot at trying to
explain it as I understand it.
When you use script/generate to set up the basic scaffolding, it adds a
“map.resources” line for the appropiate controller into your routes.rb
which gives you the (6 I believe) basic functions “for free”. That’d be
index, new, create, destroy, etc.
If you want something other than those, you need to set up the routes
yourself in the config.rb by using a map.connect in order to tell rails
how to connect up a route to an action. You do NOT get those for free
and it’s not just a simple matter of putting a def in or dropping a view
into place. You have to config the route itself.
FWIW, you don’t even have to have an index/show/etc method defined in
the controller. The default action will render any view you have with
the appropriate name by default so if you have an index view, it will
render it even without having an index method defined in the controller
at all.
Try it… you’ll see.
Rails gives you a lot for free. It doesn’t give you everything
though. You still have to do a little bit of work.
Right Gary - that’s the conclusion I came to after watching the
screencast. I’ve been on and off with the AWDR book (maybe 50%
through)
and I’m probably going to pick up another book to supplement.
On Fri, 18 Jan 2008 13:56:57 -0800, Gary Foster wrote:
FWIW, you don’t even have to have an index/show/etc method defined in
the controller. The default action will render any view you have with
the appropriate name by default so if you have an index view, it will
render it even without having an index method defined in the controller
at all.
How does this relate to creating an interface for has_many :through (if
I
may shift the topic)? This map relates to the controller how please?
Rails 2.0 uses RESTful application design, have a look at the section
on REST in that book as most of the stuff shown in it is now useless.
Google everyhing you can about rest and rails2.0
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.