Forum: Ruby on Rails Controller links and login 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.
1f5a4e0a8b163639ad448ac380d8b756?d=identicon&s=25 Sylvain Petit (sobert)
on 2008-12-21 15:54
(Received via mailing list)
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 : <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 :

[login.html.erb]
<% form_for(@Player) do |f| %>
 <%= f.error_messages %>
  <p>
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.text_field :password %>
  </p>
  <p>
  <%= f.submit "Login" %>
    </p>
  <% 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 !
Ed437e52d8d6720308720e7e678f3e6d?d=identicon&s=25 Patrick Doyle (Guest)
on 2008-12-21 17:25
(Received via mailing list)
On Sun, Dec 21, 2008 at 7:03 AM, Sobert <sokaos@gmail.com> 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
This topic is locked and can not be replied to.