开发者

Rails Devise Help

开发者 https://www.devze.com 2023-04-08 09:51 出处:网络
Can someone give me an example of how to do something like this. I have a user setup with devise, according to the way in this tutorial

Can someone give me an example of how to do something like this. I have a user setup with devise, according to the way in this tutorial https://github.com/fortuity/rails3-subdomain-devise/wiki/Tutorial-%28Walk开发者_开发问答through%29 (I skipped the stuff related to subdomain) now say if I wanted to have a user make many tweets, so a user and a user alone can upload tweets, but anyone can see them, how would that be accomplished. I find rails really tough, so if you could explain thoroughly that would be good (i.e. go to routes.rb insert get 'users/ ...)


Devise is simply an authentication gem. If you want to post tweets to Twitter, you're going to have to get into omniauth with devise. Theres a railscast for that: http://railscasts.com/episodes/236-omniauth-part-2

And devise has a wiki on direct integration: https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

If you're talking more hypothetically about creating and showing posts then after you have devise set up, just make filters on what users can do like this

before_filter :authenticate, :only => [:new, :create, :edit, :destroy]

That would go in the Posts controller right under the class declaration. Basically it says before you load pages new, create, edit, or destroy make sure the user is authenticated by calling authenticate (I believe devise already has that authenticate method built in but if not it is easy to write). Then any person could go to the show method to see the tweets, but could not create them for that user.

0

精彩评论

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

关注公众号