I Think a validation will only work after data is entered. With 
authorization (as in CanCan) the possibility of creating a new proposal can 
be avoided all together.

I did some experiments but yes, it's possible to put extra arguments into 
the initialize method.

For instance, initialize(user, project_proposal=nil).

In case you want to check you could use
ability=Ability.new(user,project_proposal)
ability.can? :create, :proposal

should give you a true or false based on what project_proposal was entered.

Ace




On Wednesday, November 14, 2012 6:22:17 PM UTC-4, Colin Law wrote:
>
> On 13 November 2012 23:07, Stan McFarland 
> <[email protected] <javascript:>> 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? 
>
> It might be easier to do it with a validation rather than cancan, or 
> would that not do what you want? 
>
> Colin 
>

-- 
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/-/kbRbd3FnP5sJ.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to