Railsで/blog/:year/:month/:dayで日付の投稿を複数表示させたい(1)
厳しそうだが、、、tryしている段階
(参考)
http://egoblock.hatenablog.com/entry/2014/08/16/003042
2014-08-16
Rails routes.rbで動的セグメントを制限する
[sourcecode language='ruby' padlinenumbers='true']
get '/:year(/:month(/:day))' => 'calendar#index',:constraints =>{ :year => 'YYYY',:month =>'MM', :day =>'DD'}
[/sourcecode]
http://qa.atmarkit.co.jp/q/3547
Rails4のページングを含むルーティングについて
[sourcecode language='ruby' ]
namespace :posts do
get 'index'
get 'page/:page', action: :index
scope ':year', year: /\d{4}/ do
get 'page/:page', action: :index
scope ':month', month: /\d{1,2}/ do
get 'page/:page', action: :index
scope ':day', day: /\d{1,2}/ do
get 'page/:page', action: :index
end
end
end
end
[/sourcecode]
http://qiita.com/ryonext/items/4ed2f7635135a7b388f3
Railsで特定の日の新規ユーザ数などを取るクエリを作る
ryonextが2015/03/13に投稿(2015/03/14に編集)
[sourcecode language='ruby' ] range = Date.yesterday.beginning_of_day..Date.yesterday.end_of_day User.where(created_at: range) User.where(created_at: 1.day.ago.all_day) [/sourcecode]
config/routes.rb
http://invoketwoa.hatenablog.com/entry/20111110/1320891631
2011-11-10
rails 日付のルーティングぶひー
[sourcecode language='bash' ]
get "/hoge/:year:month" => "hoge#show", :constraints => { :year => /[1-9][0-9]{3}/, :month => /[01][0-9]/ }
上記の例だと
http://****/hoge/2011/12
でアクセスした場合、 hoge コントローラの show アクションが呼ばれる。
params[:year] = 2011,
params[:month] = 12
がそれぞれ取得できる
[/sourcecode]
http://stackoverflow.com/questions/25399736/rails-4-blog-year-month-title-with-clean-routing
[sourcecode language='bash' ]
get "/operations/:year:month:day" => "operations#index", :constraints => { :year => /[12][0-9]{3}/, :month => /[01][0-9]/, :day => /[0-3][0-9]/ }
上記の例だと
http://****/operations/2011/12/05
でアクセスした場合、 operations コントローラの index アクションが呼ばれる。
params[:year] = 2011,
params[:month] = 12
params[:day] = 05
がそれぞれ取得できる
[/sourcecode]
なるほどわからん、試行錯誤中
[sourcecode language='bash' ]
scope "/blog" do
resources :year, controller :operations, only: :show, path: "" do
resources :month, controller :operations, only: :show, path: "" do
resources :title, controller :operations, only: :show, path: ""
end
end
end
[/sourcecode]
[sourcecode language='ruby' ]
def show
case true
when params[:year].present?
@operations = Operation.where "created_at >= ? and created_at < ?", params[:year]
when params[:month].present?
@operations = Operation.where "created_at >= ? and created_at < ?", params[:month]
when params[:day].present?
@operations = Operation.where "created_at >= ? and created_at < ?", params[:day]
when params[:id].present?
@operations = Operation.find params[:id]
end
end
[/sourcecode]
どうだか、、、
http://d4-1977.hatenablog.com/entry/2014/01/28/100213
20140128
Rails で 期間指定(between)をしてデータを取り出す
[sourcecode language='ruby' ] scope :created_at_limit, where(:created_at=> 6.months.ago..Time.now) [/sourcecode]

ディスカッション
コメント一覧
まだ、コメントがありません