Now I will explain how to use partial template in CakePHP 3, which is created like Rails. The Japanese document of CakePHP 3 is not up to date, but English document is.
Continue reading CakePHP3 How to use partial template like in RailsTag Archives: Rails
Rails How to execute task in seed
Here’s how I executed task in seeds.rb
, in Rails.
Environment
- Ruby 2.2.2p95
- Rails 4.1.8
- Rake 10.4.2
First, create a task with rails g task sample shot
. The following code will be generated.
Now, we can execute the task with bundle exec rake sample:shot
. The goal is to execute the task when bundle exec rake db:seed
is executed. Maybe, it is the same way to execute task in rails code.
Solution
Add the code into seeds.rb
, like below.
Environment (test, development, production) is passed, which is valid in rake db:seed
. On the above, set 'value'
to SOMETHING
. It is like FEATURES in rake db:fixture:load FIXTURES=xxxx
.
Rails gem to generate Sitemap
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 のメソッドを作ったというお話でした。