-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
current_project helper method 만들기 #51
Comments
흠... 시도해본 적 없는 거라 확신은 못 하겠네요.(..) 그래도 한 번 시도해볼까요? ㅎㅎ |
엇 나도 이거 고민하고 있었음. 현재는
|
이거에 대한 정보를 좀 찾아봤는데, 일단 project_id로 통일할 수가 있기는 한데 이러면 convention이 깨지는 거라서 문제가 생길 수 있다고 하고, 깔끔하게 통일하는 방법 자체도 없는 것 같음. 통일이 안 된다면
|
으흐흐... 포기? ㅋㅋ |
음 일단 제가 생각했던 방식은 # projects_controller.rb
before_action :retrieve_current_project
def retrieve_current_project
project_id = params[:id]
@current_project = Project.find_by_id(project_id)
end
# histories_controller.rb, todos_controller.rb
before_action :retrieve_current_project
def retrieve_current_project
project_id = params[:project_id]
@current_project = Project.find_by_id(project_id)
end
# application_helper.rb
def current_project
@current_project
end 위와 같습니다.
before_action으로 프로젝트 밀어넣어주는 건 �메타 프로그래밍이나 include 등을 통해서 해결할 수 있을 것 같은 느낌도 들었어요. (이 컨트롤러에서는 project 객체를 사용한다라는 의미의 DSL을 도입한다는 의미로) # project_controller.rb
own_resource :project # own_resource는 before_action에서 id로 리소스를 가져와줌.
# histories_controller.rb
parent_resource :project # parent_resource는 before_action에서 project_id로 리소스를 가져와줌. 지금 문제가 이러한 관계가 routes에서만 정의되어 있고 컨트롤러 사이에서는 모른다는 점인 것 같습니다. 근데 만약 한 컨트롤러에서 project_id로써 다른 이름을 사용하는 액션이 생기는 순간 귀찮아질 것 같더라구요. # project_resource_relation.rb (가칭)
class ProjectResourceRelation
owner :project
child :history, except_action: { name: 'blahblah', as: 'prozect_id' }
child :todo
end 를 하면 current_project를 컨트롤러 on_load에 집어넣어 줍니다 (..) 물론 지금은 이러한 예외가 없어서 최소한의 노력으로 구현을 해볼 수 있을 것 같은 생각도 들지만 지금은 배보다 배꼽이 큰 느낌이네요. 구현한다고 하면 천천히 구현해도 될 것 같다는게 제 생각입니다. |
뭔가 엄청 복잡하네요.(..) |
정말 우연하게 이런 젬을 발견했습니다. 제 생각이랑 비슷한 것 같습니다만 https://github.com/hashrocket/decent_exposure#scoping-your-object-queries 이런 느낌으로 적용하지 않을까.. |
하하하... 저 젬을 제가 한국에서 유행시킬려고 적극 밀었다가, 욕을 바가지로 먹은 적이 있죠.(..) |
방향은 비슷한데 역시 그런 점은 피할 수 없을 것 같네요. 비슷한데 제가 제일 마지막에 언급했던 방식으로 구현한 젬은 없는지 궁금하네요 ㅋㅋ 그렇다고 해도 이상한 코드가 잔뜩 .. |
음... 제가 알기로는 없습니다.(먼산) |
일단 Pending 상태로 걸어두는 것이 좋을 것 같습니다. 그동안 제가 천천히 구현해보고 있겠습니다! |
ㅇㅋ 확인했습니다. 요런건 pending 라벨 같은걸 붙일까요? |
네 우선은 보류하는게 좋을것 같습니다. |
@shaynekang 멘토님 혹시 https://github.com/josevalim/inherited_resources 이거 써보셨나요? |
아니요. 하지만 많이 들어봤습니다. ㅋㅋ(José Valim 은 레일즈의 유명한 메인테이너거든요) |
current_user 처럼 current_project 메소드가
ApplicationHelper
에 있으면 좋을 것 같은데, 어떻게 생각하시나요? 이를 위해서 routes.rb에서부터 project id parameter를 project_id로 통일해주는 것이 좋을 것 같은데..The text was updated successfully, but these errors were encountered: