我正在尝试按照在rails上的ruby中制作推文克隆的教程(http://www.youtube.com/watch?v=oXr1jAsBlPI&feature=relmfu)。不幸的是,他在Rails 2.x.x中这样做,我在跟上时遇到了一些麻烦。我现在是41:34,他在routes.rb
中定义路径。
当我进入'show'页面时,我遇到了这个问题:
“路由错误没有路由匹配{:action =>”show“, :controller =>“toggle_follow”}尝试运行rake路线以获取更多信息 有关可用路线的信息。“
这就是我在相关文件中的内容:
match '/:username', :controller => 'home', :action => 'show'
match '/:username/toggle_follow', :controller => 'home', :action => 'toggle_follow'
<% if current_user.is_friend? @user %>
<%= submit_tag "Following", :class => "button" %>
<% else %>
<%= submit_tag "Stop following", :class => "button" %>
<% end %>
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
...
提前致谢
答案 0 :(得分:1)
好的,我解决了......
在您必须输入的路线中:
匹配'/:用户名',:to =&gt; 'home#show',:as =&gt; 'user_flits' 匹配'/:用户名/ toggle_follow',:to =&gt; 'home#toggle_follow',:as =&gt; 'toggle_follow'