having a bit of an issue here with rjs and partials
i have the following controller/action:
class Admin::UsersController < ApplicationController
def new
@user = User.new
@permissions = Permission.find(:all)
@action = “create”
render :update do |page|
page.replace_html(“user_form_message”, “”)
page.replace_html(“user_form”, :partial => “user_form”, :locals =>
{
:user => @user, :permissions => @permissions })
end
end
def edit
@user = User.find(@params[:id])
@permissions = Permission.find(:all)
@action = “update”
render :update do |page|
page.replace_html(“user_form_message”, “”)
page.replace_html(“user_form”, :partial => “user_form”, :locals =>
{
:user => @user, :permissions => @permissions })
end
end
end
and the user_form partial:
<%= form_remote_tag :url => { :controller => “/admin/users”, :action =>
@action } %>
<%= text_field :user, :login, :size => 10, :class => “field”, :onfocus
=> "
this.className=‘field_selected’", :onblur => “this.className=‘field’” %>
<% permissions.each do |perm| -%>
<%= check_box_tag “user[permission_ids][]”, perm.id, @
user.permissions.include?(perm) -%><%= perm.description -%>
<% end -%>
<%= text_field :user, :name, :size => 30, :class => “field”, :onfocus =>
"
this.className=‘field_selected’", :onblur => “this.className=‘field’” %>
<%= submit_tag “Submit”, :class => “button” -%>
<%= hidden_field :user, :id %>
<%= end_form_tag %>
the problem i am having is that when the new action is rendered, the
form is
displayed empty as it should…but when the edit action is rendered, the
user fields are still blank. it appears that the form fields are
expecting
to have @user accessible. if i remove the :locals from the render call
(and
change the partial to use the instance vars as well), rails complains
that
@permissions is empty, so it appears that the instance vars are not even
available within the partial. is there a way to fix this behavior?
Chris