Hello,
I'd link to know your opinion about where should I put some JS logic, In a
form i put it all in the submit button, and in another I put it in the
controller. See:

*First way:*

Form:
<%= submit_to_remote 'Save', 'Save',
:url => {:action => 'update', :id => @folder},
:update => 'main_tab_content',
:before => 'loading()' ,
:complete => "unloading();tree.refreshFolder('#...@folder.parent.id}')" %>

Controller:
def update
    @folder = Folder.find(params[:id])
    if @folder.update_attributes(params[:folder])
      flash[:notice] = 'Folder was successfully updated.'
      redirect_to :action => '_edit', :id => @folder
    else
      render :action => 'edit'
    end
  end


*Second way:*
*
*
Form:
<%= submit_to_remote 'Create', 'Create',
  :url => {:action => 'create'},
:before => 'loading()',
:complete => 'unloading();' %>

Controller:
def create
    parent = Folder.find_by_id(params[:target_id])
    @folder = parent.children.create(params[:folder])
    if parent && @folder.save
      flash[:notice] = 'Folder was successfully created.'
      render :update do |page|
        page.replace_html 'main_tab_content', :partial => 'edit'
        page.call 'tree.refreshFolder', @folder.parent.id.to_s
      end
    else
      render :action => 'new'
    end
  end




First way let the  controller cleaner and the submit call more complex.
Second way is the opposite.
What's the preferred way? What would make the application easier to maintain
at the end?

Thanks

Mathieu

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to