Forum: Ruby on Rails What's the best way to embed a form?

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.
softwareengineer 99 (Guest)
on 2006-02-04 20:25
(Received via mailing list)
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
Xavier N. (Guest)
on 2006-02-04 20:37
(Received via mailing list)
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/ActionControlle...

-- fxn
softwareengineer 99 (Guest)
on 2006-02-04 20:47
(Received via mailing list)
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. <removed_email_address@domain.invalid> 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/ActionControlle...

-- fxn
softwareengineer 99 (Guest)
on 2006-02-04 20:47
(Received via mailing list)
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 <removed_email_address@domain.invalid> 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. <removed_email_address@domain.invalid> 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/ActionControlle...

-- fxn


_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails



---------------------------------
Relax. Yahoo! Mail   virus scanning helps detect nasty
viruses!_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
softwareengineer 99 (Guest)
on 2006-02-04 20:53
(Received via mailing list)
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 <removed_email_address@domain.invalid> 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 <removed_email_address@domain.invalid> 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. <removed_email_address@domain.invalid> 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/ActionControlle...

-- fxn


_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails



---------------------------------
Relax. Yahoo! Mail      virus   scanning helps detect nasty
viruses!_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails



---------------------------------
 Yahoo! Mail - Helps protect you from nasty
viruses._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Tom M. (Guest)
on 2006-02-04 22:14
(Received via mailing list)
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:

http://blogs.msdn.com/ie/archive/2005/04/20/410240.aspx

--
-- Tom M.
softwareengineer 99 (Guest)
on 2006-02-04 22:14
(Received via mailing list)
I am using SSL for the entire app so security is not an issue here.
  Thanks
  Frank

Tom M. <removed_email_address@domain.invalid> 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:

http://blogs.msdn.com/ie/archive/2005/04/20/410240.aspx

--
-- Tom M.
Xavier N. (Guest)
on 2006-02-04 22:14
(Received via mailing list)
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
softwareengineer 99 (Guest)
on 2006-02-04 22:36
(Received via mailing list)
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/...
, 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. <removed_email_address@domain.invalid> 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
Xavier N. (Guest)
on 2006-02-04 23:31
(Received via mailing list)
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
softwareengineer 99 (Guest)
on 2006-02-05 00:26
(Received via mailing list)
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
softwareengineer 99 (Guest)
on 2006-02-05 00:38
(Received via mailing list)
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 <removed_email_address@domain.invalid> 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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Xavier N. (Guest)
on 2006-02-05 01:56
(Received via mailing list)
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
softwareengineer 99 (Guest)
on 2006-02-05 01:56
(Received via mailing list)
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 %><br/>
          <%= form_input :password_field, "password", :size => 30
%><br/>
            <%= 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
softwareengineer 99 (Guest)
on 2006-02-05 01:56
(Received via mailing list)
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: <table class="main" align="center">
  12:


  I appreciate your assistance.

  Thanks
  Frank

softwareengineer 99 <removed_email_address@domain.invalid> 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 %><br/>
          <%= form_input :password_field, "password", :size => 30
%><br/>
            <%= 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
removed_email_address@domain.invalid
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
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
Xavier N. (Guest)
on 2006-02-05 11:05
(Received via mailing list)
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".
softwareengineer 99 (Guest)
on 2006-02-05 19:48
(Received via mailing list)
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. <removed_email_address@domain.invalid> 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".
softwareengineer 99 (Guest)
on 2006-02-05 20:18
(Received via mailing list)
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
Byron S. (Guest)
on 2006-02-05 20:24
(Received via mailing list)
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 ]
softwareengineer 99 (Guest)
on 2006-02-05 21:22
(Received via mailing list)
Byron,
  Thank you for your reply.

  That did the trick.

  Big thanks to Xavier also for spending a great deal of his weekend on
assisting me.

  ROR is the future.

  Frank

Byron S. <removed_email_address@domain.invalid> 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 ]

On 2/5/06, softwareengineer 99 <removed_email_address@domain.invalid  >
wrote: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


Xavier N. <removed_email_address@domain.invalid> wrote:    On Feb 4, 2006, at 
23:53,
softwareengineer 99 wrote:

> Thank you Xavier for your reply:



---------------------------------
 Yahoo! Mail - Helps protect you from nasty viruses.

_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails






--
Byron
http://byron.saltysiak.com
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
softwareengineer 99 (Guest)
on 2006-02-06 04:30
(Received via mailing list)
Thanks Byron for your reply.

  Frank

Byron S. <removed_email_address@domain.invalid> 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 ]
Mark W. (Guest)
on 2006-02-08 11:06
(Received via mailing list)
I've got an RXML file in the view for a model and an empty reference to
the desired view in my controller. While I am producing the XML I want,
I am also generating an HTML header that contains:

<html>
<head>
            <title>.
            <link>.
</head>
</body>

<p style.

I was under the impression that just by naming the file .rxml and then
putting XML-generating instructions in the file, I should get pure XML
but apparently I was mistaken.

How do I ditch this unwanted addition/header to my result?

Thanks,

-Mark
Ben M. (Guest)
on 2006-02-08 19:44
(Received via mailing list)
Are you perhaps getting a layout in there too? Just a wild stab in the
dark....

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