# Rjs and partials

**URL:** <https://www.ruby-forum.com/t/rjs-and-partials/84204>\
**Category:** Rails\
**Created:** [March 20, 2006, 4:09pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204 "2006-03-20T16:09:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 4:09pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/1 "2006-03-20T16:09:27Z")

</div>

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” -%\>&nbsp;&nbsp;  
\<%= 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

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 5:01pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/2 "2006-03-20T17:01:13Z")

</div>

Are you using the RJS plugin or Edge rails?

On 3/20/06, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> page.replace_html("user_form_message", "")
> page.replace_html("user_form_message", "")
> 
> ```
> 
> \<%= text\_field :user, :login, :size =\> 10, :class =\> “field”, :onfocus =\>  
> \<%= hidden\_field :user, :id %\>
> 
> Chris
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 5:17pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/3 "2006-03-20T17:17:41Z")

</div>

plugin.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 5:53pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/4 "2006-03-20T17:53:30Z")

</div>

Chris,

I thought so. I just added the patch from the trunk that fixed that.  
Try updating your plugin. You should get Rev 18.

On 3/20/06, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > i have the following controller/action:  
> > end  
> > end  
> > \<% permissions.each do |perm| -%\>
> > 
> > available within the partial. is there a way to fix this behavior?
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/5 "2006-03-20T18:31:32Z")

</div>

Cody,

maybe i’m doing something wrong here, so forgive me.

$\> script/plugin update javascript\_generator\_templates  
Updating plugin: javascript\_generator\_templates  
svn: ‘javascript\_generator\_templates’ is not a working copy

i originally installed using the command

script/plugin install javascript\_generator\_templates

i guess i could do a remove and install again, i just want to make sure  
i’m  
doing it the correct way.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/6 "2006-03-20T18:34:10Z")

</div>

Chris,

Maybe just nuke the javascript\_generator\_templates folder and  
re-install the plugin using script/plugin install  
javascript\_generator\_templates.

The install must have done an svn export and not an svn checkout.

On 3/20/06, Chris H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> script/plugin install javascript\_generator\_templates  
> Try updating your plugin. You should get Rev 18.
> 
> > > having a bit of an issue here with rjs and partials  
> > > page.replace\_html(“user\_form”, :partial =\> “user\_form”, :locals =\>  
> > > page.replace\_html(“user\_form\_message”, “”)  
> > > @action } %\>  
> > > “this.className=‘field\_selected’”, :onblur =\> " this.className=‘field’"  
> > > is  
> > > Chris  
> > > –  
> > > Rails mailing list
> 
> * * *

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [March 20, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/rjs-and-partials/84204/7 "2006-03-20T18:42:45Z")

</div>

OK, done and done, now have revision 18.

restarted WEBrick and voila, works as expected.

Thanks again!

Chris
