# Please check this simple code

**URL:** <https://www.ruby-forum.com/t/please-check-this-simple-code/116585>\
**Category:** Rails\
**Created:** [October 7, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/please-check-this-simple-code/116585 "2007-10-07T17:16:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 5:16pm UTC](https://www.ruby-forum.com/t/please-check-this-simple-code/116585/1 "2007-10-07T17:16:19Z")

</div>

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 %\> |

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 5:35pm UTC](https://www.ruby-forum.com/t/please-check-this-simple-code/116585/2 "2007-10-07T17:35:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/please-check-this-simple-code/116585/3 "2007-10-07T18:05:35Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![demoversion](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4491bb/32.png) [@demoversion](https://www.ruby-forum.com/u/demoversion)\
**Post date:** [October 7, 2007, 8:03pm UTC](https://www.ruby-forum.com/t/please-check-this-simple-code/116585/4 "2007-10-07T20:03:32Z")

</div>

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
