2011-09-27 3 views
1

나는 최근에 양식 제출시 수정 된 필드 목록을 보여주기 위해 노력 해왔다. 유일한 문제는 내 양식 (간단한 양식 사용)은 일부가있을 때 오류를 표시하지 않으며 양식을 제출할 수 없다는 것입니다. 여기 레일즈 3의 간단한 폼 문제

는 내 코드를 단순화 것 :

def update 
    @wizard.assign_attributes(params[:wizard]) 
    # Get changed attributes 

    if @wizard.save 
    # Set the success flash with fields modified 
    redirect_to @wizard 
    else 
    @title = "Edition du profil" 
    render 'edit' 
    end 
end 

보기 :

<%= simple_form_for @wizard do |f| %> 
    <%= f.input :email %> 
    <%= f.input :story %> 

    <%= f.submit "Modifier", :class => "btn success small" %> 
<% end %> 

모델 :

class Wizard < ActiveRecord::Base 
    has_secure_password 

    attr_accessible :email, :story, :password, :password_confirmation, :password_digest 

    serialize :ranks, Array 

    validates_presence_of :email, :first_name, :last_name, :gender, :story 
    validates_presence_of :password, :password_confirmation, :unless => Proc.new { |w| w.password_digest.present? } 

    # Other validations here 

    has_one :subject, :foreign_key => "teacher_id" 

    ROLES = %w[teacher] 

    scope :with_role, lambda { |role| {:conditions => "roles_bitmask & #{2**ROLES.index(role.to_s)} > 0"} } 

    # Other functions here 
end 

사람에게 생각을 했습니까?

미리 감사드립니다.

+0

또한보기 코드도 게시해야합니다. –

+0

알겠습니다. 게시판은 – Cydonia7

+0

입니다. 어디에서 'assign_attributes'를 얻었습니까? (레일 3.1과 관련하여'update_attributes'는 이전 버전에서 더 일반적으로 사용됩니다)? 마법사에서 일하러 가고 있습니까? –

답변

3

아마도 AR을 덮어 쓰는 방법과 관련이 있습니다. assign_attributes에 문제가있는 플러그인을 기억합니다. 그 동안 시도해 볼 수 있습니다 :

@wizard.assign_attributes(params[:wizard], :without_protection => true) 

그럴 경우 적어도 질량 할당 문제를 좁혀줍니다.

+0

사실, fieldset_tag에 양식의 파일을 래핑하는 문제를 해결했습니다. 나는 이유를 이해할 수 없다. – Cydonia7

0

아마도 편집/새보기에서이 부분이 누락되었습니다. 여기 @wizard은 (는) model_name입니다. 이 코드를 form 태그에 씁니다.

<% if @wizard.errors.any? %> 
     <div id="error_explanation"> 
      <h2><%= pluralize(@wizard.errors.count, "error") %> prohibited this task from being saved:</h2> 

      <ul> 
      <% @wizard.errors.full_messages.each do |msg| %> 
       <li><%= msg %></li> 
      <% end %> 
      </ul> 
     </div> 
    <% end %> 
+0

사실, 다른 양식에서는 간단한 양식이 내 자신의 CSS 스타일링과 함께 자동으로 수행됩니다. 제가 여기서 찾고있는 것은 이것이 여기에없는 이유입니다. – Cydonia7

+0

게시물보기 코드 –