rails 技術ブログ

rails 技術ブログ

勉強したことをアウトプットしていきます

2020-12-03から1日間の記事一覧

assign_attributesとは

assign_attributesとは Active Recordで用意されている、特定のattributeを変更するためのメソッド。 def update @article.assign_attributes(article_params) if @article.save flash[:notice] = '更新しました' redirect_to edit_admin_article_path(@arti…

三項演算子について

例① @article.state = @article.publishable? ? :published : :publish_wait ↑の書き方は三項演算子というもの。 条件 ? 結果1 : 結果2 これは以下のように書き換えられる。 if 条件 結果1 else 結果2 end つまり、例1は以下と同じ意味 (@article.state = @a…