rails form_tag, select

2008. 10. 1. 03:47

form_for 과 form_tag 가 약간 호환이 안되다 싶은데, api를 보면,
form_tag의 select는
select_tag(name, option_tags = nil, options = {})
이렇게 나와있다.

즉,
<%= select 'category', nil, {} %>와 같이 중간의 옵션태그를 빼먹지 말고 써줘야, 연동이 된다.
Posted by Elegant Universe
acts_as_taggable_on_steroids 플러그인과 will_paginate 플러그인을 둘다 사용할 경우에 막히네...

여러 코드 찾아 돌아당겨보며 적용해도
(http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/)
이런 방안이 있는데, 현재 will_paginate 버전에서 계속 적용이 안되서,

http://github.com/mislav/will_paginate/tree/master
에서 예전버전을 찾아 적용했는데도 find_all_by_tag 메서드를 못찾겠다는 소리가 나온다.

acts_as_taggable_on_steroids 플러그인은, 쉽게 태그를 생성, 찾을 수 있고, 태그클라우드 까지 가능한 플러그인.
will_paginate는 페이지 번호를 적용할 때, 기존의 sql문을 통해 접근할 필요 없이,

-view
<%= will_paginate @articles %>

-controller
// 기본 페이지 번호
@articles = Article.paginate   :page => params[:page], :order => 'created_at DESC', :per_page => 10
// 분류별 페이지 번호
@articles = Article.paginate_by_board_id @board.id, :page => params[:page], :order => 'updated_at DESC'
// 태그별 페이지 번호
 ---안됨--

이렇게 손쉽게 페이저번호 붙일 수 있는 플러그인.

사실, 이 페이지번호 쪽이 제일 성가시고 까다로운 부분이라, 아무래도 will_paginate 속살을 살살 벗겨봐야 겠다.
Posted by Elegant Universe

Adobe Make Some Noise

2008. 9. 20. 03:43

Adobe, MAKE SOME NOISE

Handling sound in Flash is restricted to setting the volume and panning. We want to create sound and music applications using the Flash platform but as for now the platform restricts our possibilities in many ways.

For all the other Adobe nerds: What do you need to make audio applications that rock? Contact us! info@make-some-noise.info

For Adobe, here is the list of things we wish for our work to be outstanding:

  • Writing sound bytes (amplitudes) continuously to an existing sound object.
    With the current sound capabilities its impossible to broadcast generated or modified audio to a given output. We need to use hacks or other environments (like java) to achive that. This doesn’t only mean we have to be aware of a ton of wicked things to reach the target, but more important is the fact that we loose lot of performance and/or rely to another environment to be necessary for the work.
  • High resolution timer
    For audio processing its important to have a timer that is as exact as possible and capable to process code within very short time distances. With the current situation we face the problem that the timing isn’t really exact enough for decent applications.
  • Access to the microphones amplitudes
    Right now the microphone input is life-encoded with the Nellymoser Codec. This means its impossible for us to record any input in a reasonable quality for audio processing using the flash API.
  • Multi-Threading
    Audio processing requires a lot of performance itself. But if we continue to create applications with a rich user interface we will end with only few processor cycles spared. Any heavy operation in the ui will stop the audio stream from working which is a crucial problem if we ever want to have serious output. The optimum would be to have it at the language level, so we could just require threads using regular code. But we would be satisfied if each .swf would get a seperate thread to work at, within browsers.
  • Lossy audio codec -Vorbis Codex
    In some situations we need to send or recieve audio files. The MP3 codec is outdated and of questionable quality. We would need the implementation of a proper audio codec like the Vorbis codec which is open-source (no licence costs) and produces better results.
  • Lossless audio codec - Flac support
    Recorded music from any device should be raw (as mentioned earlier). To send it to the server its important to have a codec that allows to send raw audio data in a compressed way to reduce the upload time and create faster expiriences.
  • Midi controls IO
    The input device is extremly important for creating music. Midi IO (which has been standardized) would allow to integrate the music devices into our applications.
  • Native FFT (Fast Fourier Transform) in both directions
    FFT would provide us a shortcut to the current frequency domain of sound. We could analyse and modify the spectrum of a discreet time segment. We already implemented it in AS3, but we think a native approach would be much faster. FFT is also very important for image processing.
  • Native random seed
    The current Math.random solution in Flash is not predictable. Well, you may think that random should act like this, but in many cases you like to get the same sequence of pseudo random numbers everytime you start the flash application. It is also great for game-development (predictable, but random-like behavior) and image-processing as well. A seed parameter would alter the sequence.


Posted by Elegant Universe

플렉스에선, 다른 서버의 업로드와 똑같이, 파일업로드기능 구현후 UrlRequest를 통해, url을 레일스의 컨트롤러 경로에 보낸다.

그리고, 레일스에는

Class UploadController < ApplicationController
 def load
   if saveloadFile(params[:Filedata],params[:Filename].to_s)
      render(:xml => "")
   end
 end

여기서 saveloadFile은 곧 만들게 될 정의함수이고, :Filedata, :Filename 해시를 통해 파일의 정보를 받아오게 된다. 그걸 saveloadFile 함수에 넘겨줘서 true를 호출한다면, 렌더링 된다.

  def saveloadFile(fdata, fname)
    filePath = "저장할 경로/+fname"
    if File.open(filePath, "wb") { |b| b.write(fdata.read) }
      return true
    else
      return false
    end
  end

 경로를 지정하여, 파일이름 복수문제가 있을 경우엔 Time.now() 함수 같은걸로 해당시간을 고유키로 만들어 붙이는 방식으로 해결할 수 있다.

//참고
http://mindrulers.blogspot.com/2007/04/file-upload-in-flex-rubu-on-rails_3231.html

Posted by Elegant Universe

[참고:Rails for Java Developers]
xml 파싱 중, 푸시파싱과 풀파싱.  둘다 순서대로 한방향으로 이동하며 처리되는 로직이다.
트리파싱은 전체 문서를 불러들이고 무작위로 접근. 복잡한 문서활용때 효과증가.

푸시파싱//
require 'rexml/parsers/sax2parser'
include REXML::Parsers

 targets = []
 xml ='<data><type name="a">test1</type>
             <type name="b">test2</type>
          <type name="c">test3</type></data>'
 parser = SAX2Parser.new(xml)
 parser.listen(:start_element, %w{type}) do |u,l,q,atts|  
    targets << {:name=>atts['name']}
 end
 parser.parse
 
 puts targets
=>namea
   nameb
   namec

##여기서 %w{}는 배열 생성자

풀파싱//
require 'rexml/parsers/pullparser'
include REXML::Parsers
 targets = []
 xml ='<data><type name="a">test1</type>
             <type name="b">test2</type>
          <type name="c">test3</type></data>'
 parser = PullParser.new(xml)
  parser.each do |e|
   if e.start_element? and e[0] == 'type'
     targets << {:name=>e[1]['name']}
   end
  end
 
 puts targets
=>namea
   nameb
   namec

트리파싱//
require 'rexml/document'
include REXML

targets = []
 xml ='<data><type name="a">test1</type>
             <type name="b">test2</type>
          <type name="c">test3</type></data>'
  Document.new(xml).elements.each("//type") do |e|
    targets << {:name=>e.attributes["name"]}
  end
 
 puts targets
=>namea
   nameb
   namec


빌더로 xml 생성
require 'rubygems'
require 'builder'

xml = Builder::XmlMarkup.new :type=>STDOUT, :indent=>1
xml.data do
  xml.type "test1", :name=>"a"
  xml.type "test2", :name=>"b"
  xml.type "test3", :name=>"c"
end

puts xml.to_ary
=><data>
    <type name="a">test1</type>
     <type name="b">test2</type>
     <type name="c">test3</type>
   </data>
   <to_ary/>

##레일스에 기본적으로 내장되어있는 줄 알고 있었는데, 새로 설치해야 했다. 그럴 경우 gem install builder로 설치
rails 1.x 버전은 require_gem, 2.x 버전은 그냥 require로...

[기타정보]
rexml 공식 // http://www.germane-software.com/software/rexml/
rexml api reference // http://docs.huihoo.com/rdoc/ruby/stdlib/libdoc/rexml/rdoc/index.html
builder reference // http://builder.rubyforge.org/

Posted by Elegant Universe

레일스와 호스팅

2008. 7. 22. 00:38
레일스는 확실히 손에 익어야 한다. 관례 중심이라는 확실히 그만의 장점이 있고, 코드를 정말 무지막지하게 쉽고 간단하게 만들지만, 설정,옵션으로 그것들을 대체하고 있어서 그것들을 잘알아야한다. 물론 설정,옵션도 초간단..
호스팅은 카페24만이 한국에서 유일한 루비호스팅을 받고있고, 레일스를 맵핑하려면, 도메인이 있어야 한대서, 도메인 하나 샀다. 그런데, 그거 연결하는게 여간 까다로운게 아닌데, 현재 http://도메인/컨트롤러/액션이 안먹는다. 인덱스 페이지는 뜨지만...
그리고 호스팅지원 레일스버전이 1.2버전이라, 최신버전을 다운그레이드해야 한다. 아..
조금씩 감이 오긴 오는데, 좀더 커스텀한 것을 만들기 위해서 고급적인 내용을 많이 살펴보야했다. 그런 내용들이 일관되지 않다고 해야 할까, 많이 배운다면 배울 수 있겠고,,,하지만, 살피는속도가 느리다. 뻘짓을 많이 했다.
아직, 루비언어도 생소하고... 그리고 플렉스와의 연동에서의 문제점도 봐야하고... 하지만, 아직까지 큰 문제는 없다... 잘뽑아져나온다. 근데, 기본적인 루비코드를 건드렸을때, 잘안나올때도 있고, 아직은 그거 디버깅하기도 조금 복잡하고...허나 확실한건. 진입장벽을 더 넘으면, 무지막지한 파워가 생기겠군...
Posted by Elegant Universe
황대산 님의 책을 보고 구현하다가, scaffold 부분에서 계속 막혔다.
특히 2.0 버전으로 업뎃되면서, scaffold 기능도 없어지고, sqlite로 db가 기본설정되니, 막히는 부분이 많았다.
이것 저것 찾아보면서, 드디어 해결책을 본바...

2.0버전에서 scaffold 기능 추가하는 방법은 다른데 찾아보면 자세히 설명되어 있고, 나는 귀찮아서, 최소한의 변경만 고려했다.

책의 예제들을 실행하기 위해, 필요한 부분을 나열한다.

1.  최신버전일 경우 1.2.3 버전으로 회귀한다
c:\> gem uninstall rails
c:\> gem install rails --version '= 1.2.3' --include-dependencies

2. mysql을 실행하기 위해
바로 rails phonebook이라고 해버리면,
database.yml 에 sqllite로 설정이 되버린다.

그러므로, mysql을 사용하려면

rails -d mysql phonebook

식으로 명시적으로 사용, 생성한다.
또한, database.yml 파일도 그에 맞게 수정한다.

3. mysql은 4.1이나 5.0 버전을 이용한다.
database.yml 파일 안에도 그렇게 쓰여져있고, 본인은 최신 버전인 mysql6.0을 사용하다가 피봤다. 그러므로 5.0버전 중 최신버전을 이용한다.

이렇게 하면, 아직까지는 큰 탈 없이 잘 된다.

4. rake 기능이 안먹히는 경우가 있다.
가령, rake db:migrate를 실행했을때,
c:/ruby/bin/rake.bat:24: undefined method `require_gem' for main:Object (NoMethodError)
라는 메시지를 보게 되는 경우, 해결방법은
위의 rake.bat 파일을 열어, 밑의
require_gem 'rake'version
 gem 'rake',version
로 바꾸어 준다.
아, 버전에 따라 막히는 부분들이, 슬슬 짱나...ㅜ

5. BlueCloth 라이브러리를 사용하기 위해, 설치하려고 책에 나와있는대로 실행하면,
c:/web_apps/blog_app>gem install bluecloth
Error:  could not find bluecloth locally or in a repository
라고 뜬다.
해결방안은, 명시적으로 찾아 설치하게끔 만든다.
gem query -rn Blue 라고 치면,
*** REMOTE GEMS ***
BlueCloth (1.0.0)
bluepay (1.0.1)
로 찾고
gem install -r BlueCloth 라고 치므로써
Successfully installed BlueCloth-1.0.0
설치가 된다.
Posted by Elegant Universe

카테고리

전체 (118)
Programming (15)
Digital Nomad (2)
Projects (7)
Sound (14)
Travel (69)
Think (9)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

달력

«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

글 보관함