开发者

Ruby-on-rails: routing problem: controller action looks for show when it should look for finalize

开发者 https://www.devze.com 2022-12-24 15:44 出处:网络
background: trying to use the twitter gem for ruby-on-rails. in routes: map.resources :twitter_sessions

background: trying to use the twitter gem for ruby-on-rails.

in routes:

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

(twitter_sessions is the controller for the twitter sessions in my app).

The view has one file new.html.erb and is very simple:

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

and the 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
  r开发者_运维知识库eset_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

However, after I click the "twitter" button, I get this error:

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'

If I go to the finalize url, http://localhost:3000/twitter_sessions/finalize, directly, I get this error:

Unknown action

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

Any ideas? Thanks


I'd try something a little different with your routes:

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

精彩评论

暂无评论...
验证码 换一张
取 消