Skip to content
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

Problem in accessing main root object in node and child #456

Open
mohitjain opened this issue May 21, 2013 · 4 comments
Open

Problem in accessing main root object in node and child #456

mohitjain opened this issue May 21, 2013 · 4 comments

Comments

@mohitjain
Copy link

I have a Submission model

belongs_to :report
has_many :answers

Report Model

has_many :questions

Question Model

has_many :answers   # answer has submission_id

Now in rabl template I need output like this

        object @submission
        attributes :status, :submission_time

        child :report do
            attribute :id, :name
            child :questions do
                attribute :id, :content
                node(:answers_count) do |question|
                    question.answers.where("submission_id = ?", @submission.id).count
                end
                node(:answers) do |question|
                    question.answers.where("submission_id = ?", @submission.id).collect{ |answer| {:name => answer.name, :id => answer.id}}
                end
            end
        end

This is working perfectly fine but the problem is in answers_count and answers node I am using @submission and because of that index action is not working.

Its fine in show action but index action is creating issues as @submission is not available in index action.

PS: Once I fix the issue I will move the big query from view to model. I know that, Just for simplicity I have pasted that inline.

More details can be found here on stackoverflow

@nesquena
Copy link
Owner

Question: Does report have a submission_id field?

@mohitjain
Copy link
Author

@nesquena No cause reports has_many submissions and submission belongs_to report

@mohitjain
Copy link
Author

@nesquena Any updates?

@submission
Copy link

I donot know what happened. Can anyone explain what happened here? Why
is this email sended to me?

Best wishes,
Liang

On 06/07/2013 07:08 PM, Mohit Jain wrote:

@nesquena https://github.com/nesquena Any updates?


Reply to this email directly or view it on GitHub
#456 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants