0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ruby on Rails 超簡単レベル上げ機能

Last updated at Posted at 2022-03-27

5投稿ごとに1レベ上がる。
次のレベル上がるまであと何投稿かを表示する。

users_controller
 def show
    @user = User.find(params[:id]) 
    @count = @user.tweets.count
    @level = @count / 5
    @next_level = 5 - (@count % 5)
 end
users/show.html.erb
 <h3>投稿数<%= @count %></h3>
 <h3><%= @level %>Lv</h3>
 <h3>あと<%= @next_level %>投稿でレベルup</h3>

スクリーンショット 2022-03-27 19.44.47.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?