Ruby-on-rails:路由问题:控制器动作在应该查找finalize时查找show

时间:2010-03-27 04:41:58

标签: ruby-on-rails routing twitter-gem

背景:尝试将twitter gem用于ruby-on-rails。

路线中的

map.resources :twitter_sessions
map.finalize_twitter_sessions 'twitter_sessions/finalize', :controller => 'twitter_sessions', :action => 'finalize'

(twitter_sessions是我应用中Twitter会话的控制器)。

该视图有一个文件new.html.erb,非常简单:

<% form_tag(twitter_sessions_path)  do |f| %>
   <p><%= submit_tag "twitter!" %></p>
<% end %>

和twitter_sessions_controller.rb:

def new
end

def create
  oauth.set_callback_url(finalize_twitter_sessions_url)

  session['rtoken']  = oauth.request_token.token
  session['rsecret'] = oauth.request_token.secret

  redirect_to oauth.request_token.authorize_url
end

def destroy
  reset_session
  redirect_to new_session_path
end

def finalize
  oauth.authorize_from_request(session['rtoken'], session['rsecret'], params[:oauth_verifier])

  profile = Twitter::Base.new(oauth).verify_credentials
  session['rtoken'] = session['rsecret'] = nil
  session[:atoken] = oauth.access_token.token
  session[:asecret] = oauth.access_token.secret

  sign_in(profile)
  redirect_back_or root_path
end

但是,点击“twitter”按钮后,我收到此错误:

401 Unauthorized

.../gems/oauth-0.3.6/lib/oauth/consumer.rb:200:in `token_request'
.../gems/oauth-0.3.6/lib/oauth/consumer.rb:128:in `get_request_token'
.../gems/twitter-0.9.2/lib/twitter/oauth.rb:32:in `request_token'
.../gems/twitter-0.9.2/lib/twitter/oauth.rb:25:in `set_callback_url'
app/controllers/twitter_sessions_controller.rb:7:in `create'

如果我直接转到最终网址http://localhost:3000/twitter_sessions/finalize,我会收到此错误:

Unknown action

No action responded to show. Actions: create, destroy, finalize, isLoggedInToBeta, login_required, and new

有什么想法吗? 感谢

1 个答案:

答案 0 :(得分:4)

我会尝试一下little different with your routes

map.resources :twitter_sessions, :collection { :finalize => :get } #use correct verb