1

我正在尝试按照教程在 ruby​​ on rails (http://www.youtube.com/watch?v=oXr1jAsBlPI&feature=relmfu) 中制作 Twitter 克隆。对我来说不幸的是,他在 Rails 2.xx 中这样做,我在跟上时遇到了一些麻烦。我目前是 41:34,当时他正在定义routes.rb.

当我进入我的“显示”页面时,我遇到了这个问题:

“路由错误没有路由匹配 {:action=>"show", :controller=>"toggle_follow"} 尝试运行 rake 路由以获取有关可用路由的更多信息。”

这是我在相关文件中的内容:

路线.rb

match '/:username', :controller => 'home', :action => 'show'
match '/:username/toggle_follow', :controller => 'home', :action => 'toggle_follow'

显示.html.rb

<% if current_user.is_friend? @user %>
    <%= submit_tag "Following", :class => "button" %>
<% else %>
    <%= submit_tag "Stop following", :class => "button" %>
<% end %>

home_controller.rb

def show
    @user = User.find_by_username(params[:username])
    @flits = @user.all_flits

end

def toggle_follow
    @user = User.find_by_username(params[:username])
    if current_user.is_friend? @user
        flash[:notice] = "You are no longer following @#{@user.username}"
        current_user.remove_friend(@user)
    else 
        current_user.add_friend(@user)
        flash[:notice] = "You are following @#{@user.username}"
    end

   redirect_to user_flits_path(@user.username)

end

...

提前致谢

4

1 回答 1

1

好的,我解决了...

在您必须输入的路线中:

路由.db

匹配 '/:username', :to => 'home#show', :as => 'user_flits' 匹配 '/:username/toggle_follow', :to => 'home#toggle_follow', :as => 'toggle_follow'

于 2012-04-23T12:39:52.583 回答