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 !
on 2008-12-21 16:54
on 2008-12-21 18:25
On Sun, Dec 21, 2008 at 7:03 AM, Sobert <email@example.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