小编zac*_*chj的帖子

Rails:Cookie溢出omniauth twitter注册

我正在使用omniauth让人们注册/登录Facebook并且运行良好!但我想添加omniauth-twitter gem让他们与Twitter联系.

我按照与设置Facebook连接时相同的步骤进行操作:https://github.com/plataformatec/devise/wiki/OmniAuth : -Overview

但是当我注册/进入时,我收到以下错误:

ActionDispatch::Cookies::CookieOverflow in OmniauthCallbacksController#twitter
Run Code Online (Sandbox Code Playgroud)

在以下网址:

http://localhost:3000/users/auth/twitter/callback?oauth_token=HRjON8J4bj9EcbjiELHcpHmSXo0cPd0wCHyuWG8ATZU&oauth_verifier=ZiZb1FAKZmNML1gVu5RKBLEGzbeAPPzC80QCpPDGU
Run Code Online (Sandbox Code Playgroud)

我在类似的帖子上尝试了不同的东西,但没有一个工作:(

这是我的配置:

omn​​iauth_callbacks_controller.rb => app/controllers/omniauth_callbacks_controller.rb

def twitter
    # You need to implement the method below in your model (e.g. app/models/user.rb)
    @user = User.find_for_twitter_oauth(request.env["omniauth.auth"])

    if @user.persisted?
      sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
      set_flash_message(:notice, :success, :kind => "twitter") if is_navigational_format?
    else
      session["devise.twitter_data"] = request.env["omniauth.auth"]
      redirect_to new_user_registration_url
    end
  end
Run Code Online (Sandbox Code Playgroud)

user.rb => app/models/user.rb

def self.find_for_twitter_oauth(auth)
  where(auth.slice(:provider, :uid)).first_or_create do |user|
    user.provider = auth.provider
    user.uid …
Run Code Online (Sandbox Code Playgroud)

twitter facebook ruby-on-rails devise omniauth

5
推荐指数
1
解决办法
2297
查看次数

Rails:允许用户仅对引脚进行一次upvote

我的rails应用程序中有一个upvote系统,允许用户提升Pin.但是我想限制只有一次Pin的upvote的能力.

应用程序/控制器/ pins_controller.rb

  def upvote
    @pin = Pin.find(params[:id])
    @pin.votes.create
    redirect_to(pins_path)
  end
Run Code Online (Sandbox Code Playgroud)

应用程序/模型/ pin.rb

class Pin < ActiveRecord::Base

    belongs_to :user

    has_many :votes, dependent: :destroy

    has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }
    has_attached_file :logo, :styles => { :medium => "300x300>", :thumb => "100x100>" }

    end
Run Code Online (Sandbox Code Playgroud)

应用程序/配置/ routes.rb中

  resources :pins do
  member do
    post 'upvote'
  end
end
Run Code Online (Sandbox Code Playgroud)

我不确定如何实现这一点,因为我试图实现一个允许用户只投票一次的系统,这不是我想要的,我希望他们能够只投票一次"PIN".我知道acts_as_votable gem提供了这个功能,但由于我没有使用它,我想知道是否有办法在我自己的代码上实现它.

有任何想法吗?

更新:此方法每个引脚只允许一个投票.看@Ege解决方案

让它适用于此:

def upvote
  @pin = Pin.find(params[:id])

  if @pin.votes.count == 0
     @pin.votes.create
     redirect_to(pins_path)
  else flash[:notice] =  "You …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails vote pins

2
推荐指数
1
解决办法
1680
查看次数

rails:style will_paginate with bootstrap links

我的will_paginate上有一个我想自定义的bootstrap样式!:

我的分页链接的图像

正如您在我的图像上看到的,我想隐藏页面数量,只显示上一个和下一个标签.

我成功地自定义了下一个和上一个标签的图标,如下所示:在config/locales/en.yml中:

  will_paginate:
    previous_label: <i class="fa fa-angle-left" style="color:black"></i>
    next_label: <i class="fa fa-angle-right" style="color:black"></i>
Run Code Online (Sandbox Code Playgroud)

但我真的坚持隐藏这个标签的过程.有任何想法吗?

css ruby-on-rails will-paginate twitter-bootstrap

2
推荐指数
1
解决办法
4357
查看次数