Tag Archives: Ruby

Rails: How to Solve devise error undefined method failure_app for nil class


I bumped into the following error when I was creating API program. The origin was devise gem.

NoMethodError (undefined method `failure_app’ for nil:NilClass)

Environment

  • Ruby 2.2.3p173
  • Rails 4.2.4
  • devise 3.5.2

Origin

I used sign_in method for unauthorized user.

The API in construction, we have to make unauthorized user able to login, so I wrote logging in procedure for all users, including unauthorized users. Then, devise and warden rejected unauthorized user and raised error.

Solution

Write the following setting into config/initializer/devise.rb.

Or write the following method into the model class that is used by devise for authentication. User class for example.

I recommend latter solution.

confirmation_period_valid?

confirmation_period_valid? method is defined at the module Devise::Models::Confirmable of devise gem.


Rails 4 : Load Seed from TSV


Some days ago, I was requested to enable to load seed data from excel, by my client, in rails 4 project. I told that data to be edited should be managed in database, not excel. But he really requested excel, then I and he decided load data from tsv. Excel is functional, so TSV is appropriate.

Select data area and copy and paste with mouse, Excel data can be pasted as TSV data to text editor, and vise versa.

Environment

  • Ubuntu 14.04 LTS
  • Rails 4.1.8
  • Ruby 2.2.2

Direction

  1. Create feature to load TSV data as a task, and enable to execute with rake.
  2. On executing rake db:seed, execute the task to load TSV.
Continue reading Rails 4 : Load Seed from TSV

The Way I Used Magnum CI for Rails Test


Magnum CI is a CI environment which we can use for free. Here, I wrote how I setup Rails code into Magnum CI, which is managed at Bitbucket.

Continue reading The Way I Used Magnum CI for Rails Test

Rails: The Code to show Tooltip


This is the story I tried to show tool tip in Ruby On Rails.

It’s simple. Show help message when it is clicked, and hide message when it is clicked again. はてなマークがクリックされたらツールチップを表示・非表示するということです。

I used javascript (jQuery) and CSS. And I created useful method in helper as follows.

Environment

  • Ruby 1.8.7p374
  • Rails 3.0.1
  • jQuery 1.4.3

Base

上のように javascript と css を記述して、次のように HTML を書きます。

image/quotation.png はクリックするモノです。その画像をクリックすると表示・非表示が切り替えます。

正確にいうなら、画像を囲んでいる span をクリックすると、その直後のタグの表示・非表示を切り替えます。つまりクリックするものは画像でなくてもよく、もっというならツールチップ以外にも使えるということです。

Use helper

Rails prepares helper component.

このメソッドを次のようにして使うと、上に書いた HTML のように出力されます。

Second argument has default value, so we don’t have to set any value to it.

私がこの tooltip 表示を書き始めたら ほかの人が随所で真似し始めたので、もっと楽にできる helper のメソッドを作ったというお話でした。