Hmmm.... this kinda makes sense to me, only it didn't work.  The proposed? 
method works correctly, but the can? method in my template returns true for 
both proposed and non-proposed ProposalRequests.   I'm having a hard time 
getting my head around validating a Proposal against it's parent when the 
Proposal hasn't even been created yet.  

Thanks,

Stan



On Wednesday, November 14, 2012 5:00:07 AM UTC-5, Ace Suares wrote:
>
> I assume you would need to know if
>
> proposal_request.proposals.collect { |p| p.user_id }.include? user.id
>
> so maybe you want something in the ProposalRequest like
>
> def proposed?(user)
>   proposals.collect { |p| p.user_id }.include? user.id
> end
>
> Now I assume that upon creating a Proposal, it already has a belongs_to 
> relation with the current PorposalRequest, but I am not quite sure of it.
> can :create, Proposal |proposal| do
>   proposal.proposal_request.proposed? user
> end
>
> Cheers
> ace
>
>
>
> On Tuesday, November 13, 2012 7:07:51 PM UTC-4, Stan McFarland wrote:
>>
>> Hi,  RoR newbie here.  Fairly new, anyway. :). I have a cancan question 
>> I'm hoping someone can help me with.  I have two models - ProposalRequest 
>> and Proposal.    Each ProposalRequest can have many Proposals, but a given 
>> user can submit only one Proposal for each ProposalRequest.  I can't figure 
>> out how to define the rule in ability.rb for the create action.   Can 
>> someone help?
>>
>> Thanks
>>
>> Stan McFarland
>>
>>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/5knPaqVhkEEJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to