Forum: Ruby on Rails render a partial on buttonclick?

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.
Daniel S. (Guest)
on 2007-04-20 19:08
(Received via mailing list)
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.
Brian H. (Guest)
on 2007-04-20 19:22
(Received via mailing list)
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" } %>

  <div id="login_form">
  </div>


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.
Daniel S. (Guest)
on 2007-04-20 19:41
(Received via mailing list)
oh wow that does sound easy, I'm gonna try it out. I'll respond on how
it works out...
Thanks so much!
Daniel S. (Guest)
on 2007-04-20 23:13
(Received via mailing list)
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 %>
    <table id="login">
        <tr>
            <td class="loginCell">
                <label for="name">username:</label>
                <%= text_field_tag :name, params[:name] %>
            </td>
            <td class="loginCell">
                <label for="pasword">password:</label>
       <%= password_field_tag :password, params[:password] %>
            </td>
            <td class="loginCell">
                <%= submit_tag "Login" %>
            </td>
        </tr>
    </table>
<% 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'} %>

<div id="loginPartial">
</div>
=========================================================

and the problem is that it is rendering the main "login/index.rhtml"
instead of my partial... any idea why?
Brian H. (Guest)
on 2007-04-20 23:32
(Received via mailing list)
What's your controller's action look like that does the rendering?
Niels Meersschaert (Guest)
on 2007-04-21 00:42
(Received via mailing list)
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
jacqui (Guest)
on 2007-04-21 13:19
(Received via mailing list)
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
Daniel S. (Guest)
on 2007-04-23 08:29
(Received via mailing list)
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'} %>
==========================================================
Daniel S. (Guest)
on 2007-04-23 08:32
(Received via mailing list)
I'm looking for the same effect as http://www.digg.com when you click
login...
Gokhan A. (Guest)
on 2007-04-23 18:17
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


<div id="container"><div id="header"><div id="login-form"
style="display:none;">
 <form action="/login" id="side-login" method="post">
  <label for="side-username">Username:</label>
  <input type="text" name="side-username" id="side-username" size="15"
tabindex="1" />
  <label for="side-password">Password:</label>
  <input type="password" name="side-password" id="side-password"
size="15" tabindex="2" />
  <label for="side-persistent">Remember Me?</label><input
type="checkbox" name="side-persistent" id="side-persistent"
tabindex="3"/>
  <input type="submit" value="Sign In" class="log2" tabindex="4" />
  <input type="hidden" name="processlogin" value="1" />
 </form>
</div>


and
<a href="/login" onclick="return(toggleLogin())">Login</a>



Daniel Scrima wrote:
> I'm looking for the same effect as http://www.digg.com when you click
> login...
This topic is locked and can not be replied to.