Logo F2FInterview

Ruby Rails Interview Questions

Q   |   QA

Filters enable controllers to run shared pre and post processing code for its actions.

Filter methods are macro-style, that is, they appear at the  top of your controller method, inside the class context,  before method definitions.

the below types of filters in ruby

before_filter,
after_filter,
prepend_before_filter,
prepend_after_filter,
around_filter 

Ruby is Dynamic object oriented programming language . we can use it for any application like java, or we can use it  for web programming language  

Ruby On Rails developed in 1992.But now it is spreading all over.Coding using ROR is easy we can easily develop web  applications.We can develop webservers and Ajax also can b  implemented in ROR.Similarly we have some disadvantages in  it like the User Interface and easily can do the wrong  things.Finally It is easy to learn and easy to implement  also.Learn it,It has good future. 

form_for and form_tag both are used to submit the form in ruby on rails.  but the way of handling objects related to model is  different.

form_for:

you should use form_for for a specific model i.e while  crating an new row in database. form_for will perform the  standard http post which is having fields related to active
record objects.

here is the example for using form_for in ruby on rails:

<% form_for :user, @user, :url => { :action => "update" }
do |f| %>

then in here you can use the f object to create input  field.

First name: <%= f.text_field :firstname %>
Last name : <%= f.text_field :lastname %>
Biography : <%= f.text_area :biography %>

<% end %>

form_tag:

form_tag just creates an form as an normal form. form_for  will perform the standard http post without any model  backed and has normal fields. this is used mainly when
specific things need to be submitted via form


here is the example for using form_tag in ruby on rails:

<% form_tag '/posts' do -%>
<%= text_field_tag "post", "firstname" %>
<% end -%>  

Conventional web application transmit information to and from the sever using synchronous requests. This means you fill out a form, hit submit, and get directed to a new page with new information from the server. When you interact with an Ajax-powered web page, it loads an Ajax engine in the background. In response to an event web application passes asynchronous request (XMLHttpRequest or xhr). In fact it is javaScript object/method that performs asynchronous interaction with the server, JavaScript object that performs asynchronous interaction with the server and behind the scene fetches data. and behind the scene fetches
data. We do request.xhr? only to check the request type, either its AJAX request or others(post, get). 

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: