# Controller links and login form

**URL:** <https://www.ruby-forum.com/t/controller-links-and-login-form/156144>\
**Category:** Rails\
**Created:** [December 21, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/controller-links-and-login-form/156144 "2008-12-21T15:54:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@sobert](https://www.ruby-forum.com/u/sobert)\
**Post date:** [December 21, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/controller-links-and-login-form/156144/1 "2008-12-21T15:54:13Z")

</div>

Hello,

I currently have two workarounds in my rails app :

The first, and I think the most simple :  
I’m unable to get links for controllers made with script/generate  
controllers. I made an “index” controllers, and a “news” method in it.  
I’d like to link\_to like :

- \<%= link\_to ‘News’, news\_index\_path %\>\</  
li\> but it don’t work. What I’m missing here ?

The second : I have a form for players to login. I get a dangerous  
glitch : it add user in database instead of logging.

Here’s the code :

[login.html.erb]  
\<% form\_for(@Player) do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.text\_field :name %\>

\<%= f.text\_field :password %\>

\<%= f.submit "Login" %\>

 \<% end %\>

[login in index.html.erb]  
def login  
if request.get?  
session[:current\_user]=nil  
@Player = Player.new  
else  
@Player = Player.new(params[:player])  
#logged\_in\_user = @Player.try\_to\_login  
if logged\_in\_user  
session[:current\_user]=logged\_in\_user  
else  
flash[:notice] = “Utilisateur invalide”  
end  
end  
end

[methods in player’s model]  
def self.login (name, password)  
find(:first, :conditions =\> [“name = ? and password = ?”, name,  
password])  
end

def try\_to\_loggin  
Player.login(self.name, self.password)  
end

Once again, what I’m missing here ?

Any help is apprecied.

Thanks !

---

<div class="post-metadata">

**Author:** ![sobert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@sobert](https://www.ruby-forum.com/u/sobert)\
**Post date:** [December 21, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/controller-links-and-login-form/156144/2 "2008-12-21T17:25:40Z")

</div>

On Sun, Dec 21, 2008 at 7:03 AM, Sobert [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

What does your routes.rb file look like? In order to get named routes  
(such  
as “news\_index\_path”) you would need to have something in your routes  
file  
that looks like:

ActionController::Routing::Routes.draw do |map|

map.news\_index ‘index/news’ :controller =\> :index, :action =\> :news  
end

Note also, that the latest fashion in RoR is to follow the conventions  
implied by RESTful routing. Under these conventions (which are just  
conventions, not rules), you would probably want to name your controller  
“news” and the default action (which is a Rails convention, not just  
RESTful  
convention) is the “index” action.

I’m not sure how to answer the rest of your questions, but I hope this  
helped a little bit.

–wpd
