Forum: Ruby on Rails Controller links and login form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sylvain P. (Guest)
on 2008-12-21 16:54
(Received via mailing list)

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 : <li><%= 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 :

<% 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?
      @Player =
      @Player =[:player])
      #logged_in_user = @Player.try_to_login
      if logged_in_user
        flash[:notice] = "Utilisateur invalide"

[methods in player's model]
def self.login (name, password)
    find(:first, :conditions => ["name = ? and password = ?", name,

  def try_to_loggin
    Player.login(, self.password)

Once again, what I'm missing here ?

Any help is apprecied.

Thanks !
Patrick D. (Guest)
on 2008-12-21 18:25
(Received via mailing list)
On Sun, Dec 21, 2008 at 7:03 AM, Sobert <removed_email_address@domain.invalid> 

What does your routes.rb file look like?  In order to get named routes
as "news_index_path") you would need to have something in your routes
that looks like:

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

  map.news_index 'index/news' :controller => :index, :action => :news

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
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.

This topic is locked and can not be replied to.