1
1

More than 5 years have passed since last update.

自分用メモ1

Last updated at Posted at 2018-01-07

バージョンが変わってない

問題
ダウンロードは出来てるのにバージョンが切り替わらなかったら

解決

$ eval "$(rbenv init -)"

パスもこれでおkだた

rbenvでバージョンがうまく切り替わらなかった時にやったこと
https://qiita.com/akatsuki174/items/c0384b9903b4b5cbbdaf

10分でRailsブログを作成

問題2

$ bundle install

でrbenv: bundle: command not found

解決

$ gem install bundler

新しいRubyのバージョンをインストールするとbundle installできない
https://qiita.com/opiyo_taku/items/f4459ce4f42e18d08e28

メモ
サーバー立ち上げた後、ターミナルを別窓開いたら、当たり前だけど

$ cd blog

して入る

ここでまた

$ eval "$(rbenv init -)"

問題

$ rails generate controller Comments
`
でターミナルに出るエラー

undefined method `resources' for main:Object (NoMethodError)

routes.rbないのend抜けてた

これまでずっとハマってたとこはターミナルをちゃんと読めばわかった

問題
コメントできない
ActiveModel::ForbiddenAttributesError
なんかセキュリティらしい
http://ruby-rails.hatenadiary.com/entry/20140813/1407915718

Railsではセキュアなアプリケーションの開発を促すためにいくつかのセキュリティ機構が存在します。そして、今そのセキュリティ機構によりエラーが発生しました。この機構は、Strong Parametersと呼ばれ、Railsは、私たちに「パラメーターのどの値を取得したいか」をコントローラー内に明示することを要求しています。今回の場合で言うと、パラメーター内のtitleとtextの値を取得したいので、次のように変更して下さい。

ForbiddenAttributesErrorが発生
http://jangajan.com/blog/2014/09/24/forbiddenattributeserror-in-rails/

これを見て

class CommentsController < ApplicationController

def new

end

  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(params[:comment])
    redirect_to post_path(@post)
  end

  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end

end

こうなってたのを

class CommentsController < ApplicationController

def new

end

  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(comment_params)
    redirect_to post_path(@post)
  end


  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end


  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end

end

こうした。

問題
コメントが「削除」で消せなかった
destroyのactionが見つかんないと言われたので

解決

上記の

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end

を下にしたらできた

class CommentsController < ApplicationController

def new

end

  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(comment_params)
    redirect_to post_path(@post)
  end





  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end

  private
    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end

end

ここにきて毎回バージョンとパスがリセットされることにいらついてきた
でも仕様らしい

# bash起動時にrbenvの初期化を行うように設定。
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
1
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
1
1