Please check this simple code

Hello,

Please check my code for creating feedbacks on my application.
Code is simple, because I’m new to RoR and only studying(It’s working
but i’m not sure about method render :action=>:index, because somewhere
i read that better to use redirect_to method):

class Leave::FeedbackController < ApplicationController
layout ‘base’
def index
@feedback = Feedback.new
end
def theend
begin
@feedback = Feedback.new(params[:feedback])
@feedback.added_at = Time.now
if @feedback.save
flash[:notice] = “Feedback succesfully created”
return
else
render :action => :index
end
rescue Exception => ex
logger.debug “Error while adding new feedback, ex=” + ex.to_s
end
end
end

<% form_for :feedback, :url=> {:action => :theend} do |form|%>

<%= error_messages_for 'feedback' %>

Author:
<%= form.text_field :author, :size => 20 %>
Feedback text:
<%= form.text_area :feedback_text, :size=>'40x10'%>
Email:
<%= form.text_field :email, :size => 20 %>

<%= submit_tag "Send feedback" %>

<% end %>

On 7 Oct 2007, at 16:16, Igor K. wrote:

Hello,

Please check my code for creating feedbacks on my application.
Code is simple, because I’m new to RoR and only studying(It’s working
but i’m not sure about method render :action=>:index, because
somewhere
i read that better to use redirect_to method):

render :action is not better than redirect_to, it’s just different.
render makes rails use a different template, redirect_to makes the
browser resubmit a request to the specified url.

Both have their place, although it is true that there are cases where
one is preferable than they other.

One of the cases where you do want to use render is when validation
of some user submitted form has failed (in particular if you did
redirect_to :action => :index then you’d lose all the stuff the user
submitted)

Fred

One of the cases where you do want to use render is when validation
of some user submitted form has failed (in particular if you did
redirect_to :action => :index then you’d lose all the stuff the user
submitted)

Yes I noticed that i used redirect_to i loose my validation errors.

Finally do you think this code good enough? because i only starts from
feedback model and i still need to implement 10 models more in this way.

Thanks

On 7 Oct 2007, at 17:05, Igor K. wrote:

feedback model and i still need to implement 10 models more in this
way.

It’s a fairly standard pattern

Fred