-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Oct 3, 2005, at 12:37 PM, Robert Boone wrote:> I don''t even know where to start explaining what''s wrong
with this.
> I''m
> trying to render to the previous form after an exception but I
> have to
> put a return after it so it will not fall through the rest of the
> program. What am I doing wrong here.
First, move some of your core biz logic into your model:
class Person < ActiveRecord::Base
belongs_to :user, :foreign_key => ''riscid''
validates_presence_of :user, :message => ''Gold Card number not
found.''
before_create :set_status_to_user_grp
private
def set_status_to_user_grp
self.status ||= user.grp
end
end
I find it easiest to manage control flow by using a single action to
both show the form and handle its submission. It makes it very easy
to show the form again when your form submission has errors.
class FooController < ApplicationController
def edit
# Set up instance variables, etc. necessary to render the form.
@person = Person.find(params[:id])
@current_month, @dorms, @sems = ...
# Handle form submission when we have a POST request.
if request.post?
# Save the person. If no validation errors, redirect.
# If invalid, re-render the form and show errors
if @person.update_attributes(params[:person])
redirect_to :action => ''show'', :id => @person
end
end
# Fall through and render app/views/foo/edit.rhtml unless we were
# redirected back to the show action by a successful form
submission.
end
end
Your view, app/views/foo/edit.rhtml, posts back to the same action:
<%= form_tag :action => ''edit'', :id => @person %>
...
</form>
Best,
jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)
iD8DBQFDQZgcAQHALep9HFYRArZ6AKC2SkZ8by6ikNsjYHIQloMnZX3YqACcCNNJ
e1mRrxRDsenJzKriYnIUhXg=ITbM
-----END PGP SIGNATURE-----