Forum: Ruby on Rails validates... :if => Proc.new{...} does not find a method!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joshua M. (Guest)
on 2006-03-24 11:48
Hi all

I wanted to use the following validation in my model Party:

validates_presence_of :organisator_name,
                      :if => Proc.new{ member.organisators.empty? }

I have written the member method in the ApplicationController:

class ApplicationController < ActionController::Base
  def member
    session[:member]
  end
end

But it does not seem to be known by the Party Model...

Any help, please? :-)

Greetings,
Josh
Joshua M. (Guest)
on 2006-03-24 14:38
Joshua M. wrote:
> Hi all
>
> I wanted to use the following validation in my model Party:
>
> validates_presence_of :organisator_name,
>                       :if => Proc.new{ member.organisators.empty? }
>
> I have written the member method in the ApplicationController:
>
> class ApplicationController < ActionController::Base
>   def member
>     session[:member]
>   end
> end
>
> But it does not seem to be known by the Party Model...
>
> Any help, please? :-)
>
> Greetings,
> Josh

OK, I found the problem now. The models can't know the method member,
because it's only declarated in the controllers... How can I import this
method into the models?

Thanks for help.
This topic is locked and can not be replied to.