ruby-on-rails-4

Rails 4 + Devise 3.0 - Authenticate using username and email

徘徊边缘 提交于 2020-01-16 01:00:35
问题 I'm trying to allow users to sign in with either their username or their email address. as per here: https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-sign-in-using-their-username-or-email-address When ever I try to sign in with either the email or the login this is logged: Started POST "/users/sign_in" for 192.168.2.8 at 2013-11-22 10:11:50 +0800 Processing by Devise::SessionsController#create as HTML Parameters: {"utf8"=>"â", "authenticity_token"=>

Rails adds `AND (1=0)` to queries

不打扰是莪最后的温柔 提交于 2020-01-16 00:46:34
问题 Rails somehow adds AND (1=0) to the SQL query of a model: CompanyRelation Load (0.2ms) SELECT `company_relations`.* FROM `company_relations` WHERE `company_relations`.`vendor_id` = 1 AND (1=0) 回答1: Also you can find 1=1 or 1=0 in your query if you do where(params[:data]) and data it's a hash with empty values. For example you have params hash live { village: { directions: { id: Empty Array }}} 回答2: Seems to be an issue with CanCan: http://github.com/ryanb/cancan/issues/733 回答3: This is the

redirect_url is missing in email instructions sent to the user for password reset

戏子无情 提交于 2020-01-15 23:57:10
问题 I am trying to build api urls for password reset via. devise_token_auth gem. As per the usage mentioned here, the POST request for /api/v1/auth/password needs params email and redirect_url . The user matching the email param will be sent instructions on how to reset their password. redirect_url is the url to which the user will be redirected after visiting the link contained in the email. However, I am getting the following URL in the email for password reset, in which the param redirect_url

Is it the Rails way to use form helper markup?

核能气质少年 提交于 2020-01-15 17:36:23
问题 I am reading the guide on form helpers http://guides.rubyonrails.org/form_helpers.html but I'm not sure whether I actually need to write my webpages this way.. I have an HTML form like this written in new.html.erb <form action="/posts" method="post"> <label for="title">Test</label> <input id="title"/> <input type="submit" value="submit"/> </form> (The posts page is from the Getting Started guide) When I submit the request, the server throws an ActionController::InvalidAuthenticityToken

Disable cache digests in Rails 4

吃可爱长大的小学妹 提交于 2020-01-15 17:32:04
问题 I'm in the process of migrating a Rails 3 app to Rails 4. The migration was mostly fairly smooth, but one big problem I'm encountering is that my old Rails 3 code to expire my caches isn't working. I'm getting logs like: Expire fragment views/localhost:3000/cardsets/36?action_suffix=edityes (0.0ms) ... Read fragment views/localhost:3000/cardsets/36?action_suffix=edityes/d8034b6e68ba30b5916a2ebb73b68ffe (0.0ms) This turns out to be because Rails 4 brings a new funky kind of caching, cache

Rails 5: Jquery autocomplete

牧云@^-^@ 提交于 2020-01-15 11:25:03
问题 I have implemented the jquery autocomplete within my rails app. And this is the setup: //= require jquery //= require rails-ujs //= require jquery-ui //= require bootstrap //= require_tree . items.js $(document).ready(function() { $("#search").autocomplete({ source: "/search_suggestions", autoFocus: true, select: function(event, ui) { $(event.target).val(ui.item.value); $('#search').closest("form").submit(); return false; } }); }); this is the search action inside the model items.rb def self

how to use searchkick to index according to some conditions

故事扮演 提交于 2020-01-15 10:12:32
问题 I am using searchkick and rails4. I have an activerecord People, with attributes a,b,c. How can I do indexing only when b equals "type1", not indexing otherwise? Currently what I know is def search_data { a:a, b:b, c:c, } end 回答1: Per the docs: By default, all records are indexed. To control which records are indexed, use the should_index? method together with the search_import scope. This should work for your case: class People < ApplicationRecord searchkick # you probably already have this

Twitter Card Validator error when in development

孤人 提交于 2020-01-15 07:44:09
问题 I'm having an issue validating my Twitter Card in development. I have configured my router's public IP to point to my internal LAN IP/port http://119.21.79.135:3000 Given the meta tags are in place; <meta name="twitter:card" content="photo" /> <meta name="twitter:site" content="@flickr" /> <meta name="twitter:title" content="Mountain sunset" /> <meta name="twitter:description" content="Explore Reza-Sina's photos on Flickr. Reza-Sina has uploaded 113 photos to Flickr." /> <meta name="twitter

Single Table Inheritance in Rails 4

自闭症网瘾萝莉.ら 提交于 2020-01-15 06:42:18
问题 I'm trying to implement a somewhat simple STI in Rails 4, but there's something I can't yet manage to achieve. I have the following classes: class Person < ActiveRecord::Base end class NaturalPerson < Person end class LegalPerson < Person end class Employee < NaturalPerson end class Customer < NaturalPerson end The thing is, I have some attributes that I want to access only from the Employee class, some only from Customer, etc, but I can't find the way. If I were to be using Rails 3's way I

Upgrading Rails 3.2 to Rails 4 and Params

百般思念 提交于 2020-01-15 06:39:06
问题 I was upgrading my project from Rails3 to Rails4 with this tutorial: RailsCasts I have a model: class Test < ActiveRecord::Base validates :content, :presence => true, :length => { :minimum => 2 } validates :name, :presence => true, :length => { :minimum => 2 } validates :value, :presence => true end After upgrading, in rails console I tried to create new test object Test.create(name: "asd", content:"asd", value: 5) And got WARNING: Can't mass-assign protected attributes for Achievement: name,