# Partial problem

**URL:** <https://www.ruby-forum.com/t/partial-problem/110049>\
**Category:** Rails\
**Created:** [July 22, 2007, 2:12am UTC](https://www.ruby-forum.com/t/partial-problem/110049 "2007-07-22T02:12:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 22, 2007, 2:12am UTC](https://www.ruby-forum.com/t/partial-problem/110049/1 "2007-07-22T02:12:59Z")

</div>

I created a partial for my login form and I have it in my my login view  
folder (‘login/\_login.rhtml’), When I call the partial for my login page  
login.rhtml it works fine. I have it on a layout for all pages that  
aren’t the login page, and I call it by the command:

render(:partial =\> ‘login/login’)

But when I click the submit button it does nothing.  
Any ideas on what the problem is?

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 22, 2007, 3:21pm UTC](https://www.ruby-forum.com/t/partial-problem/110049/2 "2007-07-22T15:21:56Z")

</div>

Scott Pn wrote:

> I created a partial for my login form and I have it in my my login view  
> folder (‘login/\_login.rhtml’), When I call the partial for my login page  
> login.rhtml it works fine. I have it on a layout for all pages that  
> aren’t the login page, and I call it by the command:
> 
> render(:partial =\> ‘login/login’)
> 
> But when I click the submit button it does nothing.  
> Any ideas on what the problem is?

… it looks good at a first start. maybe 'tis worth posting your code,  
as it doesn’t seem there’s any problem with what you’ve posted.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 22, 2007, 4:41pm UTC](https://www.ruby-forum.com/t/partial-problem/110049/3 "2007-07-22T16:41:58Z")

</div>

Shai R. wrote:

> … it looks good at a first start. maybe 'tis worth posting your code,  
> as it doesn’t seem there’s any problem with what you’ve posted.

## Here is what I have for my login page, which uses the \_login partial, this works fine (login/login.rhtml):

## 

# Please Login
  
\<%= render(:partial =\> “login”) %\>
## Here is my other page which is in my layout folder (layout/main.rhtml):
 \<%= controller.action\_name %\> \<%= stylesheet\_link\_tag 'scaffold' %\>

 \<% if session[:user\_id].nil? %\> \<%= render(:partial =\> "login/login") %\> \<% else %\> 

Hello, \<%= session[:username] %\>  
 \<%= link\_to "Logout", :controller =\> 'login', :action =\> 'logout' %\>

 \<% end %\> 

\<%= flash[:notice] %\>

 \<%= yield :layout %\> 

--------------------------------------------------------------------- And here is what my partial looks like (login/\_login.rhtml): --------------------------------------------------------------------- \<% form\_tag do %\> Username: \<%= text\_field\_tag :username, params[:username] %\>   
 Password: \<%= password\_field\_tag :password, params[:password] %\>   
 \<%= submit\_tag "Login" %\> \<% end %\> ---------------------------------------------------------------------

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 23, 2007, 9:43am UTC](https://www.ruby-forum.com/t/partial-problem/110049/4 "2007-07-23T09:43:52Z")

</div>

> ```
> <% if session[:user_id].nil? %>
> 
> ```
> 
> \<%= render(:partial =\> “login/login”) %\>  
> \<% else %\>

stupid question, but possible session[:user\_id] is not nil? seems it  
should work.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 26, 2007, 12:46am UTC](https://www.ruby-forum.com/t/partial-problem/110049/5 "2007-07-26T00:46:02Z")

</div>

On 7/21/07, Scott Pn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I created a partial for my login form and I have it in my my login view  
> folder (‘login/\_login.rhtml’), When I call the partial for my login page  
> login.rhtml it works fine. I have it on a layout for all pages that  
> aren’t the login page, and I call it by the command:
> 
> render(:partial =\> ‘login/login’)
> 
> But when I click the submit button it does nothing.  
> Any ideas on what the problem is?

I don’t think you have posted enough code to diagnose the problem. I’m  
guessing that is has something to do with the way you have setup the  
url params for your form, so that they’re in the right context when  
you’re executing actions in the login\_controller scope, but otherwise  
not.

Cheers,  
Obie

–  
Obie F.

> **[Best Online Casino in Australia | Top Licensed Casinos for Gamblers](https://toponlinecasinoaustralia.com)**
>
> Best Online Casino in Australia with licensed games only. Play blackjack, roulette, poker and other top-notch casino games. Enjoy gambling 24/7.

Pre-order my book The Rails Way today!  
[http://www.amazon.com/dp/0321445619](http://www.amazon.com/dp/0321445619)

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 23, 2007, 1:44pm UTC](https://www.ruby-forum.com/t/partial-problem/110049/6 "2007-07-23T13:44:02Z")

</div>

Shai R. wrote:

> > ```
> > <% if session[:user_id].nil? %>
> > 
> > ```
> > 
> > \<%= render(:partial =\> “login/login”) %\>  
> > \<% else %\>
> 
> stupid question, but possible session[:user\_id] is not nil? seems it  
> should work.

Already tested it, I thought the same thing, but If I login using  
localhost:3000/login/login where the partial is on the login page it  
works fine and when I go back to any other page with the partial on it  
the message is displayed.  
If the user is nil the partial form is displayed, but when I click  
submit nothing works, idk if I pointed that out or not, or if it makes  
any difference in differentiating the problem.

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 26, 2007, 12:46am UTC](https://www.ruby-forum.com/t/partial-problem/110049/7 "2007-07-26T00:46:32Z")

</div>

You have not provided any explicity action to form\_tag in your  
partial. That means it will post back to its current URL. When you’re  
on the login page, I’m guessing that it works fine, since it will POST  
to the /login/login action. However, anywhere else on your site it  
will not work.

Provide an action to that form\_tag and it will work. [i.e. form\_tag ‘/login/login’]

On 7/22/07, Scott Pn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= controller.action\_name %\> \<%= link\_to "Logout", :controller =\> 'login', :action =\> 'logout' %\> \<%= submit\_tag "Login" %\> \<% end %\> --------------------------------------------------------------------- -- Posted via http://www.ruby-forum.com/.
> 
> >

–  
Obie F.

> **[Best Online Casino in Australia | Top Licensed Casinos for Gamblers](https://toponlinecasinoaustralia.com)**
>
> Best Online Casino in Australia with licensed games only. Play blackjack, roulette, poker and other top-notch casino games. Enjoy gambling 24/7.

Pre-order my book The Rails Way today!  
[http://www.amazon.com/dp/0321445619](http://www.amazon.com/dp/0321445619)

---

<div class="post-metadata">

**Author:** ![dark-omen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c68b51/32.png) [@dark-omen](https://www.ruby-forum.com/u/dark-omen)\
**Post date:** [July 26, 2007, 5:09am UTC](https://www.ruby-forum.com/t/partial-problem/110049/8 "2007-07-26T05:09:00Z")

</div>

Obie F. wrote:

> You have not provided any explicity action to form\_tag in your  
> partial. That means it will post back to its current URL. When you’re  
> on the login page, I’m guessing that it works fine, since it will POST  
> to the /login/login action. However, anywhere else on your site it  
> will not work.
> 
> Provide an action to that form\_tag and it will work. [i.e. form\_tag ‘/login/login’]
> 
> On 7/22/07, Scott Pn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > \<%= controller.action\_name %\> \<%= link\_to "Logout", :controller =\> 'login', :action =\> 'logout' %\> \<%= submit\_tag "Login" %\> \<% end %\> --------------------------------------------------------------------- -- Posted via http://www.ruby-forum.com/.
> > 
> > >
> 
> –  
> Obie F.  
> [Best Online Casino in Australia | Top Licensed Casinos for Gamblers](http://jroller.com/obie/)
> 
> Pre-order my book The Rails Way today!  
> [http://www.amazon.com/dp/0321445619](http://www.amazon.com/dp/0321445619)

Yeah I actually figured that out yesterday, I realized that it wasn’t  
specifying any controller so it assumed whatever controller it was on.  
However I did encounter another problem where the controller  
specification didn’t work, even though it should (probably just a bug on  
my machine or something), but a way around it is to build your own html  
form.

Thanks for the help.
