Forum: Ruby on Rails rjs and partials

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-03-20 16:09
(Received via mailing list)
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 -%><br/>
<% 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;<input
type="button" class="button" value="Cancel"
onclick="Element.update('user_form',
'')" />
<%= 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
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-03-20 17:01
(Received via mailing list)
Are you using the RJS plugin or Edge rails?

On 3/20/06, Chris Hall <christopher.k.hall@gmail.com> 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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Cody Fauser
http://www.codyfauser.com
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-03-20 17:17
(Received via mailing list)
plugin.
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-03-20 17:53
(Received via mailing list)
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 Hall <christopher.k.hall@gmail.com> 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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>


--
Cody Fauser
http://www.codyfauser.com
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-03-20 18:31
(Received via mailing list)
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.
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-03-20 18:34
(Received via mailing list)
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 Hall <christopher.k.hall@gmail.com> 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 Fauser
http://www.codyfauser.com
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-03-20 18:42
(Received via mailing list)
OK, done and done, now have revision 18.

restarted WEBrick and voila, works as expected.

Thanks again!

Chris
This topic is locked and can not be replied to.