Hi, I was developping an application and everything was working
properely, until I decided to migrate to RoR 2.0. I was using
Scriptaculous to add new itens to a list using Highlight visual
effect. But in RoR 2.0 when I press submit button in the form, only
the partial is rendered to the browser, not the entire page, with the
new item added with highlight effect. What should I do to correct
this?
Here the code:
The partial: _area.html.erb
<li id="area_<%= area.id %>">
<div class="nome_item">
<%= area.nome -%>
</div>
<small>
<%= link_to "Editar", :action => "editar", :id => area.id %>
<%= link_to_remote "[x]", :url=> {:action => "excluir", :id =>
area.id} %>
</small>
</li>
The list in the mais view page: lista.html.erb
...
<!-- Lista areas existentes -->
<ul id="item_lista">
<%= render :partial => 'area/area', :collection => @areas %>
</ul>
...
The criar.js.rjs:
if @area.new_record?
page.alert @area.errors.full_messages.join("\n")
else
page.insert_html :top, 'item_lista', :partial => 'area'
page.visual_effect :highlight, "area_#{@area.id}"
page.form.reset 'area_form'
end
The controller: area_controller.rb
...
def lista
@areas = Area.find(:all, :conditions => ["conta_id = ?",
session[:usuario].conta], :order => "id DESC")
end
def criar
@area = Area.new(params[:area])
@area.conta = session[:usuario].conta
if @area.save
return if request.xhr?
render :partial => 'area', :object => @area
else
flash.now[:notice] = "Não deu certo. Tente novamente."
render :controller => 'area', :action => 'lista'
end
end
...
Thanks a lot.