Creating a View

(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.

Hello,
I'm new to RoR, too. It is hard to find good tutorials online, but I
found an awesome user authentication tut, located here:

http://codingbitch.com/p/comboy/User+authentication+in+Ruby+on+Rails

Also, you should read up on MVC (model, view, controller). Here is a
great article:

http://www.slash7.com/articles/2005/02/22/mvc-the-most-vexing-conundrum

The second one is really good, I really recommend it. She has other
articles, too.

Good Luck,
- Jeff Miller

longint wrote:

Thanks Jeff, I will look into those more.

I would also like to say that although http://localhost:3000/members/register
throws an error, http://localhost:3000/members/register/i_can_put_anything_here_and_it_works.

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??

I have the same problem, but I don't know how can I fix this. it seems
like a routing problem...

longint wrote:

Well at least I'm not the only one :stuck_out_tongue:

Just doesn't make sense. Even when I click on the 'Show' link it
brings up: http://localhost:3000/members/1… I would think it would
be http://localhost:3000/members/show/1. At least that's what I
gather from the AWDR book.

Any other ideas out there?

yes, look at this episode:
http://railscasts.com/episodes/35

longint wrote:

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.

Thanks.

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.

-- Gary F.

longint wrote:

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.

Thanks.

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

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?

thanks,

Thufir