ruby-on-rails-4

RoR - ArgumentError in SessionsController#create wrong number of arguments (1 for 2)

十年热恋 提交于 2020-01-24 21:48:06
问题 I am new to RoR and I am following this tutorial on making a user authentication system from scratch: http://railscasts.com/episodes/250-authentication-from-scratch. I've been hung up on this error message all weekend: ArgumentError in SessionsController#create: wrong number of arguments (1 for 2). Here is the code from my sessions controller: class SessionsController < ApplicationController def new end def create user = User.authenticate(:email => params[:email], :password => params[

Devise polymorphic association nested attributes with simple form using rails 4

左心房为你撑大大i 提交于 2020-01-24 20:20:27
问题 I am making a polymorphic association with devise and simple for but for some reason i cant get the params to work here is my code: User: class User < ActiveRecord::Base devise :database_authenticatable, :rememberable, :trackable, :validatable belongs_to :loginable, polymorphic: true end Designer: class Designer < ActiveRecord::Base has_one :user, as: :loginable accepts_nested_attributes_for :user end Layout: <%= simple_form_for [:admin, @designer] , :html => { :class => 'form-horizontal' }

images in emails using roadie gem

瘦欲@ 提交于 2020-01-24 16:56:22
问题 I want to know how to show images in email by using roadie gem. Using roadie i'm able to inline my stylesheets but it's not showing images. I have tried both <%= image_tag "pic.jpg" %> and <img src="pic.jpg"/> or <img src="assets/images/pic.jpg"/> inside my mail template, but it's not showing any of the images. Any help? 回答1: It's been a long time since I asked this question and I was pretty new to rails development so didn't really know what I was doing wrong. Anyways so the issue is when we

Select lower case column with group by or select lower(column) in Rails 4

北城余情 提交于 2020-01-24 12:34:53
问题 How to achieve following in rails 4? Here is my PostgreSQL query and works correctly SELECT lower(name) as c_name, count(*) as cc FROM categories GROUP BY c_name ORDER BY cc desc LIMIT 3 Ii gives me following results "ecommerce solutions";6 "vmware";6 "big data analytics";5 But when I write same query in Rails 4 as Category.select("lower(name) as c_name, count(*) as cc").group("c_name").order("cc desc").limit(3) Above query generates following query which is same as above PostgreSQL query

Using Delayed Paperclip With S3 Direct Upload

妖精的绣舞 提交于 2020-01-24 11:15:28
问题 I'm using Delayed Paperclip alongside direct uploads to S3. My model is called Photo and its attachment is image . Images are uploaded to S3 using JavaScript from the Photo form. The file is stored in the location that Paperclip expects the original image to be located, and the file details are saved to hidden fields. When the form is submitted, these attributes are written to the Photo model: image_file_name image_file_size image_content_type Because writing these attributes alone doesn't

How to use globalize and sunspot in rails 4

不羁的心 提交于 2020-01-24 04:30:06
问题 How do i index arabic profile translations with sunspot solr. Can i use globalize and sunspot or should use some other approach? models/profile.rb translates :name, :description validates :name validates :description searchable do text :name text :description end 回答1: You can define separate fields for each of your locales in your search block: I18n.available_locales.each do |locale| # Separate name field for each locale text "name_#{locale}".to_sym do # read_Attribute is defined by Globalize

Rails Integration Testing - How to Simulate bad CSRF token and Expired Session

核能气质少年 提交于 2020-01-23 22:47:08
问题 I just changed exception handling code in my application_controller.rb to correctly capture ActionController::InvalidAuthenticityToken . I was previously doing a rescue_from Exception that was defined after the recuse_from ActionController::InvalidAuthenticityToken. This was taking priority and my intended rescue_from code was not being executed. I'd like to write an integration test to verify this behavior. How can I create an object that will allow me to send a bad CSRF token to a post

How to Create Nested Forms in Rails 4

醉酒当歌 提交于 2020-01-23 17:07:53
问题 I'm trying to let a user create Exercises with Equipment and Muscles in many-to-many relationships through their respective join tables( exercise_equipment, exercise_muscles ). I've gotten the form working for adding one equipment/muscle per exercise, but cannot figure out how to add a link to add another field to the form on the fly. I've checked out RailsCasts, this post, have asked it as a side question on a previous post of my own, but simply cannot get this functionality to work. I'm

Using uniq in a has_and_belongs_to_many relationship in Rails 4

早过忘川 提交于 2020-01-23 11:03:26
问题 I'm trying to implement a unique constraint on a has_and_belongs_to_many relationship like so: class User has_and_belongs_to_many :foos, uniq: true end Because I only want unique foos when I call user.foos , I added the uniq option. Since upgrading to Rails 4 I've started to get the following warning: DEPRECATION WARNING: The following options in your User.has_and_belongs_to_many :foos declaration are deprecated: :uniq. Please use a scope block instead. For example, the following: has_many

Devise Confirmation invalid on first send

我是研究僧i 提交于 2020-01-23 01:47:47
问题 I have a Rails 4 app with Devise 3.2.2 using :confirmable , and am running into an issue with it sending invalid confirmation tokens, but only the first time . After you resend the confirmation token, the link works. The relevant routes: devise_for :users, skip: [:sessions, :passwords, :confirmations, :unlocks, :registrations, :invitations] as :user do ... # joining get '/register' => 'devise/registrations#new', as: 'new_user_registration' post '/register' => 'devise/registrations#create', as