문제

저자가 ROR 4를 사용하여 간단한 CMS를 만드는 비디오 시리즈를 따라 수행하지만 현재 ROR 3.x가 설치되어 있습니다.나는 모든 코드를 "T"에 따라 갔지만 단순한 CMS에서 간단한 주제를 만들려고 할 때 오류가 발생합니다.그래서 나는 log / production.log

을 확인했습니다.

와 다음 오류가 발생합니다. TypeError (no implicit conversion of Symbol into String):

컨트롤러 코드는 다음과 같습니다

def create
    # Instantiate a new object using form parameters

    # the below line should work with rails v3.x
    # @subject = Subject.new(params[:subject])

    @subject = Subject.new(subject_params)

    # Save the object
    if @subject.save
      # add flash hash
      flash[:notice] = "Subject created successfully."
      # if save succeeds, redirect to the index action
      redirect_to(:action => 'index')
    else
      # if save fails, redisplay the form so user can fix problems
      render('new')
    end
  end
.

및 피사체에 대해 작성한 개인 메소드는 다음과 같이 다음과 같습니다

 private

    def subject_params
      # same as using "params[:subject]", except that it:
      # - raises an error if :subject is not present
      # - allows listed attributes to be mass-assigned
      params.require(:subject).permit(:name, :position, :visible)
    end
.

도움이 되었습니까?

해결책

Author는 @subject = Subject.new(subject_params)@subject = Subject.new(params[:subject])로 변경해야한다는 것을 알려줍니다.

params.require(:subject).permit(:name, :position, :visible)"nofollow"> 강력한 매개 변수 라는 레일 4 기능입니다.RAILS에 새로운 경우 저자가 이와 같은 향후 버전 문제를 완화하기 위해 작성자가 사용하는 버전을 사용하는 것이 좋습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top