안녕하세요.. 루비초보개발자입니다.. ㅠㅠ 혼자서는 해결이 안되어 이렇게 또다시 글을 남기네요.....도와주세요~~

158 views
Skip to first unread message

JOJILOVE

unread,
Nov 13, 2012, 11:04:52 AM11/13/12
to rub...@googlegroups.com
 안녕하세요~~
 너무나 존경스런 루비개발자님들에게 도움이 필요하여 이렇게 소스랑 같이 글을 남기게 되었습니다.
우선 아래보시면 resource_select_tag 옆에 mo 라고 시작되는 부분이 있는데 이 mo 는 대체 무슨 용도인지를 전혀 모르겠습니다. 책을 뒤적거려봐도 모르겠고 인터넷을 찾아봐도 안나와있던데...
아시는분은 좀 알려주셨으면 좋겟습니다. 너무 간절합니다. ----------------- 이게 첫번째 질문입니다. 두번째 질문은 또다른 소스와 같이 하겠습니다.
 
1번째 질문 소스
<% @material_name.each do  |temp|%>
        <tr  name= "tr_id">
            <td><%= temp.material_id.split(@domain.id+"-")[1] %></td>
            <td><%= temp.default_qty %></td>
            <td><%= (@qty.to_f*temp.default_qty.to_f)/100.00%></td>
            <td><%= text_field_tag "mo[#{temp.material_id}][real_amount]", (@qty.to_f*temp.default_qty.to_f)/100.00 , :Onkeydown => "real_total_set();" %></td>
   <td><%= resource_select_tag "mo[#{temp.material_id}][raw_name]", 'Lot' ,"" , :search_conditions  => {:qty_1 => '>=0.001' ,:material_id=>temp.material_id.gsub("1000-","") } %></td>
   <td><%= resource_select_tag "mo[#{temp.material_id}][raw_name2]", 'Lot' ,"", :search_conditions  => {:qty_1 => '>=0.001' ,:material_id=>temp.material_id.gsub("1000-","") }%></td>
   <td><%= resource_select_tag "mo[#{temp.material_id}][raw_name3]", 'Lot' ,"", :search_conditions  => {:qty_1 => '>=0.001' ,:material_id=>temp.material_id.gsub("1000-","") }%></td>
            <% real_total += (@qty.to_f*temp.default_qty.to_f)/100.00%>
            <% bom_total += temp.default_qty.to_f%>
 
 
 
 
2.번째 질문소스
지금 밑에보시면 @domain.lots.create!(:name => @lot_type+"_"+@date+"_"+@seq_num , :seq_num=> @seq_num  <---- 요부분뒤에 :description =>  xxxxxxx 를 넣어 db에있는 description 열에 데이터를  넣고싶은데요 데이터는 위에 1번째 소스에
mo[#{temp.material_id}][raw_name]", 'Lot' ,"" , :search_conditions => {:qty_1 => '>=0.001' ,:material_id=>temp.material_id.gsub("1000-","") } %> 이분분에서 데이터가 들어옵니다 이 데이터를 description 에 넣고싶어서 그러는데 저기
xxxxxxx 라고 한부분에 어떻게 설정값을 넣어줘야하는지를 모르겠습니다. mo 자체가 뭔지를 몰라서 이리저리 해도 에러만 뜨네요... ㅠㅠ
 
@date = Time.now.strftime("%Y%m%d")
  @lot_type = 'MX'
  @temp_seq = @domain.lots.find_by_sql "select max(seq_num) as seq_num from lots where name like '"+@lot_type +"'+'_'+'"+@date+"' +'_'+ seq_num"    
  @temp_seq.each do |temp|     
    @seq_num =temp.seq_num  
  end  
  if(@seq_num == nil)     
    @seq_num = 0  
  end
  @seq_num = "%03d"%(@seq_num.to_i+1)
  @domain.lots.create!(:name => @lot_type+"_"+@date+"_"+@seq_num , :seq_num=> @seq_num ,:material_id => params[:dg_lot][:material_id]  ,:qty_1 => params[:dg_lot][:qty_1] , :lot_type => @lot_type ,:equipment_id => params[:dg_lot][:equipment], :status_flag=> "started" ,:status =>'START', :start_flag => true, :start_time => Time.now)
  flash[:notice] = t(:'notice.temp_notice', :input_name=>@lot_type+"_"+@date+"_"+@seq_num)
else
  flash[:error] = t(:'notice.qty_shortage')
 
end
 
 
혹시몰라서 전체소스도 같이 올려드리겠습니다. 제발 도와주십시요 꾸벅~~
1번째 전체소스.txt
2번째 전체소스.txt

Chang Shin

unread,
Nov 13, 2012, 11:41:35 AM11/13/12
to rub...@googlegroups.com
코드가 상당히 복잡하네요. 고생이 많으시겠어요.

<%= text_field_tag "mo[#{temp.material_id}][real_amount]", (@qty.to_f*temp.default_qty.to_f)/100.00 , :Onkeydown => "real_total_set();" %>

이부분에서 "mo[#{temp.material_id}][real_amount]" 는 input 태그의 name에 들어가게 됩니다.
그래서 폼이 submit되면 controller의 params에서 params[:mo][A_MATERIAL_NAME][:real_amount] 에 input 필드의 value가 들어오게 됩니다. params[:mo] 를 출력해 보면 이해가 빠를 겁니다.

mo는 큰 뜻은 없으며 폼에 제출될때 POST data에 포함되는 name입니다. 이것이 참조되어 controller에서 params 변수가 만들어집니다. 


description에 넣고 싶은 값이 mo[#{temp.material_id}][raw_name] 가 전해주는 값이라고 하셨는데 이 값이 하나가 아닙니다. controller에서 params[:mo]를 출력해 보면 @material_name의 수만큼 뭔가가 들어 있을 것입니다. 그 중 원하는 것을 골라서 넣어주면 됩니다. 예를 들어 첫번째 것을 넣고 싶다면 params[:mo].first[:raw_name] 가 될 듯 합니다.

수고하세요.

<1번째 전체소스.txt><2번째 전체소스.txt>

황용대

unread,
Nov 14, 2012, 6:01:03 AM11/14/12
to rub...@googlegroups.com
참고로 erb 단에서 값을 조작해서 보여주지 마시고 뷰를 위한 값을 리턴하는 메소드를 모델에 넣어주세요.
뷰는 보여주는 곳입니다

2012년 11월 14일 수요일에 JOJILOVE님이 작성:


--
http://about.me/stadia
Reply all
Reply to author
Forward
0 new messages