Render a partial on buttonclick?


#1

I currently have a link to a Login screen, but its a separate page
althogether. I have created a partial that is just the login box and
password, and would like that partial to appear at a place on the page
when the user clicks the link. Anyone know where I can find out how to
do this?

Thanks so much.


#2

You use link_to_remote instead of link_to… then you have the
destination
be a controller that just renders your partial and puts the result in
that
div. Pretty easy actually.

<%= link_to_remote “Delete this post”, :update => “login_form”,
:url => { :action => “show_login_form”, :controller=>“login” } %>

Then in your controller, assuming you have a partial at
app/views//login/_form.rhtml you just do

displays the login form partial… used by an AJAX request

def show_login_form
render :partial=>“login/form”
end

You can do a lot more cool stuff though… There’s a really good O’Reilly
shortcut on RJS, but sadly I forget what it’s called… I think it’s RJS
Templates for Rails or something. Quality read, and helps you get
started
quite quickly.


#3

oh wow that does sound easy, I’m gonna try it out. I’ll respond on how
it works out…
Thanks so much!


#4

Ok so some of it worked, but not all of it. I have the partial “app/
views/login/_login_small.rhtml” that has this:

=========================================================
<% form_tag do %>








username:
<%= text_field_tag :name, params[:name] %>

password:
<%= password_field_tag :password, params[:password] %>

<%= submit_tag “Login” %>

<% end %>

and my layout which should be the header for every page, "app/views/
layouts/application.rhtml

=========================================================
<%= link_to_remote “Login”, :update => “loginPartial”, :url =>
{:action => ‘show_small_login’, :controller => ‘login’} %>

=========================================================

and the problem is that it is rendering the main “login/index.rhtml”
instead of my partial… any idea why?


#5

Use a link_to_remote for the link. In the action it calls,

render :page do
page[:id_of_place_on_page].replace(:partial => ‘path_to_partial’)
end

don’t forget to setup the variables used in the partial in the action
as well.

Niels


#6

What’s your controller’s action look like that does the rendering?


#7

Couldn’t you also do this in your controller?

displays the login form partial… used by an AJAX request

def show_login_form
render :partial=>“login/form”, :layout => false
end

So it wouldn’t render the layout for that action?

Jacqui


#8

Here is my action:

def show_login_partial
render :update do |page|
page.visual_effect :fade, ‘loginPartial’
end
end

Here is the location of the actual link on the rhtml page:

<%= link_to_remote “Login”, :update => “loginPartial”, :url =>
{:action => ‘show_small_login’, :controller => ‘login’} %>


#9

I’m looking for the same effect as http://www.digg.com when you click
login…


#10

You can look at the source code of Digg.

They have a division where they keep hidden and when you click on it
they just show it.

Gokhan
www.sylow.net

Username: Password: Remember Me?

and
Login

Daniel Scrima wrote:

I’m looking for the same effect as http://www.digg.com when you click
login…