What's the best way to embed a form?

I would like to embed my login form on my app’s home page. What’s the
best way to render the login action of member controller from another
action?

Thanks
Frank

On Feb 4, 2006, at 19:24, softwareengineer 99 wrote:

I would like to embed my login form on my app’s home page. What’s
the best way to render the login action of member controller from
another action?

If there’s a controller that renders that form, a clean idiom is to
embed it calling render_component from the view:

http://api.rubyonrails.com/classes/ActionController/Components.html

– fxn

Thanks Xavier for your quick assistance.

The problem is that when I use
render_component :controller => “member”, :action => “login”

the original home page doesn’t render anymore.

I tried the following after rendering the above component, but then my
application stops. I am guessing it goes into an infinite loop.

render_component :controller => “home”, :action => “show”, :params =>
{ “category” => @params[:category] }

How can I render my home page, but just add the form there?

Thanks
Frank

Xavier N. [email protected] wrote: On Feb 4, 2006, at 19:24,
softwareengineer 99 wrote:

I would like to embed my login form on my app’s home page. What’s
the best way to render the login action of member controller from
another action?

If there’s a controller that renders that form, a clean idiom is to
embed it calling render_component from the view:

http://api.rubyonrails.com/classes/ActionController/Components.html

– fxn

Xavier,
I figured it out.
I was trying to put it in the controller, but if I put it in views
directory, it works

Thanks for your assistance.

Frank

softwareengineer 99 [email protected] wrote: Thanks Xavier
for your quick assistance.

The problem is that when I use
render_component :controller => “member”, :action => “login”

the original home page doesn’t render anymore.

I tried the following after rendering the above component, but then my
application stops. I am guessing it goes into an infinite loop.

render_component :controller => “home”, :action => “show”, :params =>
{ “category” => @params[:category] }

How can I render my home page, but just add the form there?

Thanks
Frank

Xavier N. [email protected] wrote: On Feb 4, 2006, at 19:24,
softwareengineer 99 wrote:

I would like to embed my login form on my app’s home page. What’s
the best way to render the login action of member controller f rom
another action?

If there’s a controller that renders that form, a clean idiom is to
embed it calling render_component from the view:

http://api.rubyonrails.com/classes/ActionController/Components.html

– fxn


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Relax. Yahoo! Mail virus scanning helps detect nasty
viruses!_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Now I am having an issue where my layout is rendered twice? My header
is showing two times, once for the home page and the second time for
the login page.

Is there a way that I can have the layout rendered only once?
Thanks
Frank

softwareengineer 99 [email protected] wrote: Xavier,
I figured it out.
I was trying to put it in the controller, but if I put it in views
directory, it works

Thanks for your assistance.

Frank

softwareengineer 99 [email protected] wrote: Thanks Xavier
for your quick assistance.

The problem is that when I use
render_component :controller => “member”, :action => “login”

the original home page doesn’t render anymore.

I tried the following after rendering the above component, but then my
application stops. I am guessing it goes into an infinite loop.

render_component :controller => “home”, :action => “show”, :params =>
{ “category” => @params[:category] }

How can I render my home page, but just add the form there?

Thanks
Frank

Xavier N. [email protected] wrote: On Feb 4, 2006, at 19:24,
softwareengineer 99 wrote:

I would like to embed my login form on my app’s home page. What’s
the best way to render the login action of member controller f rom
another action?

If there’s a controller that renders that form, a clean idiom is to
embed it calling render_component from the view:

http://api.rubyonrails.com/classes/ActionController/Components.html

– fxn


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Relax. Yahoo! Mail virus scanning helps detect nasty
viruses!_______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Yahoo! Mail - Helps protect you from nasty
viruses._______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

On Feb 4, 2006, at 10:24 AM, softwareengineer 99 wrote:

I would like to embed my login form on my app’s home page. What’s
the best way to render the login action of member controller from
another action?

Unless your users are forced to view the home page via SSL, what you
are trying to do (and is done so commonly) is not secure:


– Tom M.

I am using SSL for the entire app so security is not an issue here.
Thanks
Frank

Tom M. [email protected] wrote: On Feb 4, 2006, at 10:24
AM, softwareengineer 99 wrote:

I would like to embed my login form on my app’s home page. What’s
the best way to render the login action of member controller from
another action?

Unless your users are forced to view the home page via SSL, what you
are trying to do (and is done so commonly) is not secure:


– Tom M.

Thank you so much for your reply.

Unfortunately, I can’t get it to work.

According to
http://rails.techno-weenie.net/question/2006/1/14/render_component_infinite_loop
, its the render method that supports :layout=>false.

When I place :layout=>false in render_component, nothing happens.

When I palce render (:layout=>false ) at the end of my function, no
form is shown.

When I change render_component to render, still no form shows up.

So far: in show.rhtml, I have
<%= render :controller => “member”, :action => “login”, :layout =>
false, :params => { “member[login]” => “” } %>

When I put
render (:layout=>false)
in my tags_controller, the layout is shown 0 times.

I tried
<%= render_component :controller => “member”, :action => “login”,
:layout => false, :params => { “member[login]” => “” } %>

but it causes the layout to show two times.

I am really confused at the moment and appreciate any help.

Thanks
Frank
Xavier N. [email protected] wrote: On Feb 4, 2006, at 19:51,
softwareengineer 99 wrote:

Now I am having an issue where my layout is rendered twice? My
header is showing two times, once for the home page and the second
time for the login page.

Is there a way that I can have the layout rendered only once?

Yes, in your application the generation of the login form does not
construct an entire HTML page, it only creates a HTML form. In those
situations you need to render :layout => false.

– fxn

On Feb 4, 2006, at 19:51, softwareengineer 99 wrote:

Now I am having an issue where my layout is rendered twice? My
header is showing two times, once for the home page and the second
time for the login page.

Is there a way that I can have the layout rendered only once?

Yes, in your application the generation of the login form does not
construct an entire HTML page, it only creates a HTML form. In those
situations you need to render :layout => false.

– fxn

Xavier,
Thank you once again for your detailed reply.

I created a method named ‘login_form’ and the corresponding .rhtml
file. but now I just keep getting the following error:

“::MemberController” is not a valid constant name!

I thought one could add a new action by simply creating the method and
the .rhtml file.

What am I missing?

Any pointers are greatly appreciated.

Thanks
Frank

On Feb 4, 2006, at 21:33, softwareengineer 99 wrote:

Thank you so much for your reply.

Unfortunately, I can’t get it to work.

The idea is:

  1. In the view that generates the home you put something like this:

    <%= render_component :controller => “member”, :action =>
    “login_form” %>

  2. In member_controller.rb there’s the corresponding action whose
    only purpose is the generation of the login form:

    def login_form
    # …
    render :layout => false
    end

  3. The file login_form.rhtml generates a HTML form that calls the
    actual “login” action if submitted.

This is a technique to include HTML from other controllers, it makes
sense when the generated HTML needs to be included in several places,
when the controller is needed to take some logic into account in the
generation of the HTML, etc. If the controller is not needed then
factoring out the very form in a private template plus
render :partial in the view is another standard idiom.

– fxn

On Feb 4, 2006, at 23:26, softwareengineer 99 wrote:

Thank you once again for your detailed reply.

Sure.

I created a method named ‘login_form’ and the corresponding .rhtml
file. but now I just keep getting the following error:

“::MemberController” is not a valid constant name!

I thought one could add a new action by simply creating the method
and the .rhtml file.

What am I missing?

Can you send the smallest relevant code snippets?

– fxn

I just wanted to add to the following post that the moment I change
<%= render_component :controller => “member”, :action =>
“login_form”%>
to
<%= render_component :controller => “member”, :action => “login”%>
I don’t get the exception error.

Can anyone please guide me as to what else is required to create an
action? I have created the .rhtml file and defined the method in my
controller?

Thanks

softwareengineer 99 [email protected] wrote:
Xavier,
Thank you once again for your detailed reply.

I created a method named ‘login_form’ and the corresponding .rhtml
file. but now I just keep getting the following error:

“::MemberController” is not a valid constant name!

I thought one could add a new action by simply creating the method and
the .rhtml file.

What am I missing?

Any pointers are greatly appreciated.

Thanks
Frank


Brings words and photos together (easily) with
PhotoMail - it’s free and works with Yahoo!
Mail._______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Thank you Xavier for your reply:

Here is the views/member/login_form.rhtml (edited for html)
<%= head_helper %>
<%= start_form_tag_helper %>
<%= form_input :text_field, “login”, :size => 30 %>

<%= form_input :password_field, “password”, :size => 30
%>

<%= button_helper ‘login’ %>
<%= link_helper ‘login_signup’, :action => ‘signup’ %> |
<%= link_helper ‘login_forgot_password’, :action =>
‘forgot_password’ %>
<%= end_form_tag %>

The following is the line in views/tags/show.html

<%= render_component :controller => “member”, :action =>
“login_form”%>

If I change the above line back to login, I don’t get the exception
error.

Here are the lines from member_controller.rb

def login_form
return if generate_blank
@member = Member.new(@params[‘member’])
if @session[‘member’] =
Member.authenticate(@params[‘member’][‘login’],
@params[‘member’][‘password’])
flash[‘notice’] = l(:member_login_succeeded)
redirect_back_or_default :action => ‘welcome’
else
@login = @params[‘member’][‘login’]
flash.now[‘message’] = l(:member_login_failed)
end
render :layout => false
end

Unfortunately, since I ported my app to use SVN, I don’t have access
to log contents either (an issue I am working on fixing).

If there is anything else that you would like to see, please let me
know.

Once again, thank you very much for your assistance.

Frank

What am I missing?

Can you send the smallest relevant code snippets?

– fxn

I was able to get access to logs using the webrick server and the
following is an excerpt:

Processing MemberController#login_form (for 151.213.150.183 at
2006-02-04 15:50:05) [GET]
Parameters: {“action”=>“login_form”, “id”=>nil,
“controller”=>“member”}
Redirected to http://accounting.adoppt.com:3000/member/login
Filter chain halted as [login_required] returned false
Completed in 0.00104 (961 reqs/sec) | DB: 0.00000 (0%) | 302 Found
[http://accounting.adoppt.com/tag/business]
Start rendering component ({:controller=>“/member”,
:action=>“login”}):

ActionView::TemplateError (“::MemberController” is not a valid
constant name!) on line #9 of app/views/tags/show.rhtml:
6:
7:
8:
9: <%= render_component :controller => “member”, :action =>
“login_form”%>
10:
11:


12:

I appreciate your assistance.

Thanks
Frank

softwareengineer 99 [email protected] wrote: Thank you
Xavier for your reply:

Here is the views/member/login_form.rhtml (edited for html)
<%= head_helper %>
<%= start_form_tag_helper %>
<%= form_input :text_field, “login”, :size => 30 %>

<%= form_input :password_field, “password”, :size => 30
%>

<%= button_helper ‘login’ %>
<%= link_helper ‘login_signup’, :action => ‘signup’ %> |
<%= link_helper ‘login_forgot_password’, :action =>
‘forgot_password’ %>
<%= end_form_tag %>

The following is the line in views/tags/show.html

<%= render_component :contro ller => “member”, :action =>
“login_form”%>

If I change the above line back to login, I don’t get the exception
error.

Here are the lines from member_controller.rb

def login_form
return if generate_blank
@member = Member.new(@params[‘member’])
if @session[‘member’] =
Member.authenticate(@params[‘member’][‘login’],
@params[‘member’][‘password’])
flash[‘notice’] = l(:member_login_succeeded)
redirect_back_or_default :action => ‘welcome’
else
@login = @params[‘member’][‘login’]
flash.now[‘message’] = l(:member_login_failed)
end
render :layout => false
end

Unfortunately, since I ported my app to use SVN, I don’t have acce
ss to log contents either (an issue I am working on fixing).

If there is anything else that you would like to see, please let me
know.

Once again, thank you very much for your assistance.

Frank

What am I missing?

Can you send the smallest relevant code snippets?

– fxn


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Brings words and photos together (easily) with
PhotoMail - it’s free and works with Yahoo!
Mail._______________________________________________
Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

On Feb 4, 2006, at 23:53, softwareengineer 99 wrote:

    <%= link_helper 'login_forgot_password', :action =>  

‘forgot_password’ %>
<%= end_form_tag %>

The following is the line in views/tags/show.html

<%= render_component :contro ller => “member”, :action =>
“login_form”%>

There’s a spurious space in “:contro ller”.

I can’t say thanks enough for you continung to assist me.

I have no idea how the space got in the message. I checked with my
code and there is no space or I edited it out earlier:

<%= render_component :controller => “member”, :action =>
“login_form”%>

I spent all night trying to figure it out but to no avail.

Am I right in assuming that a method and a corresponding .rhtml file
is all that’s needed to create an action?

Frank

Xavier N. [email protected] wrote: On Feb 4, 2006, at 23:53,
softwareengineer 99 wrote:

Thank you Xavier for your reply:

Here is the views/member/login_form.rhtml (edited for html)
<%= head_helper %>
<%= start_form_tag_helper %>
<%= form_input :text_field, “login”, :size => 30 %>

    <%= form_input :password_field, "password", :size => 30 % 
      <%= button_helper 'login' %>
    <%= link_helper 'login_signup', :action => 'signup' %> |
    <%= link_helper 'login_forgot_password', :action =>  

‘forgot_password’ %>
<%= end_form_tag %>

The following is the line in views/tags/show.html

<%= render_component :contro ller => “member”, :action =>
“login_form”%>

There’s a spurious space in “:contro ller”.

You can change the rendering of layouts in a more declarative way at the
top
of controllers with something like:

layout “application”, :except => [ :login_form ]

After some digging around, I found the solution to the error:

“::MemberController” is not a valid constant name!
The error goes away if I comment out the following line in
member_controller.rb

before_filter :login_required

My MemberController has the following layout applied to it
class MemberController < ApplicationController
layout ‘default-layout’

This is causing the header to show up two times (even for my new
method login_form).

How can I have a default layout applied to a Controller and then turn
it off for one function?

Currently my tags/show.rhtml reads

<%= render_component :controller => “member”, :action =>
“login_form”%>

And my login_form definition in member_controller is:

def login_form
return if generate_blank
@member = Member.new(@params[‘member’])
if @session[‘member’] =
Member.authenticate(@params[‘member’][‘login’],
@params[‘member’][‘password’])
flash[‘notice’] = l(:member_login_succeeded)
redirect_back_or_default :action => ‘welcome’
else
@login = @params[‘member’][‘login’]
flash.now[‘message’] = l(:member_login_failed)
end
render :layout => false
end

Why isn’t the render :layout => false working here?

I thought it would be nice to have the layout applied to the entire
controller. But I didn’t know that tunring it off will become such a
hassle?

So what are the best practices in this case? Is it good to apply a
“global” layout and then turn it off for each function (which isn’t
working for me) or not have a “global” layout and then apply it for
each method?

Needless to say, I am so confused with layouts here.

Your continued assistance is highly appreciated. I am sure this will
help a lot of new learners here too.

Frank

Thanks Byron for your reply.

Frank

Byron S. [email protected] wrote: You can change the
rendering of layouts in a more declarative way at the top of controllers
with something like:

layout “application”, :except => [ :login_form ]