hello, how to use a controller method in model? example ---- in -ApplicationController def is_ok? return true unless ........ end ----- in model use is_ok? --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
why you need to do this? On Sat, Feb 7, 2009 at 11:10 PM, fmh <helmi.fatnassi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > hello, > > how to use a controller method in model? > > example > > ---- in -ApplicationController > > def is_ok? > return true unless ........ > end > > ----- in model > > use is_ok? > > > > >-- TWRUG Blog: http://blog.rubyonrails.org.tw CFC on Rails: http://zusocfc.blogspot.com Only two surfaces of a box: http://blog.pixnet.net/zusocfc --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
because i have a special controller authentication (an admin model without table) and in my model i have a method to authorize some action. On 7 fév, 16:12, CFC <zuso...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> why you need to do this? > > > > On Sat, Feb 7, 2009 at 11:10 PM, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > hello, > > > how to use a controller method in model? > > > example > > > ---- in -ApplicationController > > > def is_ok? > > return true unless ........ > > end > > > ----- in model > > > use is_ok? > > -- > TWRUG Blog:http://blog.rubyonrails.org.tw > > CFC on Rails:http://zusocfc.blogspot.com > > Only two surfaces of a box:http://blog.pixnet.net/zusocfc--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
fmh wrote:> because i have a special controller authentication (an admin model > without table) and in my model i have a method to authorize some > action.You are trying to break the MVC pattern, only bad things will happen to you, you certainly have to refactor / rethink your code. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i did this , because i dont want integrate my users admin with simple
users
class Admin < ActiveRecord::BaseWithoutTable
column :username , :string
column :userpass , :string
def self.authenticate?(username,userpass)
admin = Admin.new
admin.username = "admin"
admin.userpass = "1234"
if (admin.username == username && admin.userpass == userpass)
true
end
end
end
how to affect this admin to a current_user ?
because if my current_user is an admin user i skip my other problem
On 7 fév, 16:35, Fernando Perez
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> fmh wrote:
> > because i have a special controller authentication (an admin model
> > without table) and in my model i have a method to authorize some
> > action.
>
> You are trying to break the MVC pattern, only bad things will happen to
> you, you certainly have to refactor / rethink your code.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ok,
So once we get past the "Why would you ever want to do something dumb
like that?" and "Bad things will happen..." which I assume means
the
Rails Police will come during the night and kill your cat, how can FMH
actually get the job done?
Seriously guys, give the guy at least a pointer to a real reason not
to do what he''s trying - don''t just spit dogma.
This has worked for me with:
About your application''s environment
Ruby version 1.8.7 (powerpc-darwin9)
RubyGems version 1.3.1
Rails version 2.2.2
Active Record version 2.2.2
Action Pack version 2.2.2
Active Resource version 2.2.2
Action Mailer version 2.2.2
Active Support version 2.2.2
Application root /Users/rick/Journeys
Environment development
Database adapter postgresql
1) put your needed methods in a module in "lib/your_stuff.rb" where
your_stuff.rb looks like:
module YourStuff
protected
def thing1
...
end
end
2) add the line "include YourStuff" to the controller for the class
you want to make thing1 available in:
class PagesController < ApplicationController
include AuthenticatedSystem
or, optionally, add it to app/controllers/application.rb to make
thing1 available everywhere.
Now let''s see if there can be some reasonable discussion about why
this is a "bad idea" and how soon you should expect your cat to die.
Rick
On Feb 7, 5:50 am, fmh
<helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> i did this , because i dont want integrate my users admin with simple
> users
>
> class Admin < ActiveRecord::BaseWithoutTable
> column :username , :string
> column :userpass , :string
>
> def self.authenticate?(username,userpass)
> admin = Admin.new
> admin.username = "admin"
> admin.userpass = "1234"
> if (admin.username == username && admin.userpass == userpass)
> true
> end
> end
> end
>
> how to affect this admin to a current_user ?
>
> because if my current_user is an admin user i skip my other problem
>
> On 7 fév, 16:35, Fernando Perez
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
> wrote:
>
> > fmh wrote:
> > > because i have a special controller authentication (an admin
model
> > > without table) and in my model i have a method to authorize some
> > > action.
>
> > You are trying to break the MVC pattern, only bad things will happen
to
> > you, you certainly have to refactor / rethink your code.
> > --
> > Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
ok, i think i rushed coding this, i now rethinking my code. i am not familiar with MVC. On 7 fév, 22:27, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Ok, > > So once we get past the "Why would you ever want to do something dumb > like that?" and "Bad things will happen..." which I assume means the > Rails Police will come during the night and kill your cat, how can FMH > actually get the job done? > > Seriously guys, give the guy at least a pointer to a real reason not > to do what he''s trying - don''t just spit dogma. > > This has worked for me with: > About your application''s environment > Ruby version 1.8.7 (powerpc-darwin9) > RubyGems version 1.3.1 > Rails version 2.2.2 > Active Record version 2.2.2 > Action Pack version 2.2.2 > Active Resource version 2.2.2 > Action Mailer version 2.2.2 > Active Support version 2.2.2 > Application root /Users/rick/Journeys > Environment development > Database adapter postgresql > > 1) put your needed methods in a module in "lib/your_stuff.rb" where > your_stuff.rb looks like: > > module YourStuff > protected > def thing1 > ... > end > end > > 2) add the line "include YourStuff" to the controller for the class > you want to make thing1 available in: > > class PagesController < ApplicationController > include AuthenticatedSystem > > or, optionally, add it to app/controllers/application.rb to make > thing1 available everywhere. > > Now let''s see if there can be some reasonable discussion about why > this is a "bad idea" and how soon you should expect your cat to die. > > Rick > On Feb 7, 5:50 am, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > i did this , because i dont want integrate my users admin with simple > > users > > > class Admin < ActiveRecord::BaseWithoutTable > > column :username , :string > > column :userpass , :string > > > def self.authenticate?(username,userpass) > > admin = Admin.new > > admin.username = "admin" > > admin.userpass = "1234" > > if (admin.username == username && admin.userpass == userpass) > > true > > end > > end > > end > > > how to affect this admin to a current_user ? > > > because if my current_user is an admin user i skip my other problem > > > On 7 fév, 16:35, Fernando Perez <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > fmh wrote: > > > > because i have a special controller authentication (an admin model > > > > without table) and in my model i have a method to authorize some > > > > action. > > > > You are trying to break the MVC pattern, only bad things will happen to > > > you, you certainly have to refactor / rethink your code. > > > -- > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
fmh wrote:> ok, > i think i rushed coding this, i now rethinking my code. > i am not familiar with MVC.Q? Do you have a users table? If so then why is not the admin flag simply an attribute of user? If not then how do you identify users? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Look here for some examples on how to do role based authorization. http://www.vaporbase.com/postings/Authorization_in_Rails You can also checkout restful-authentication to support the user login type of accounts. http://github.com/technoweenie/restful-authentication/tree/master These two work well together. On Feb 7, 4:08 pm, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ok, > i think i rushed coding this, i now rethinking my code. > i am not familiar with MVC. > > On 7 fév, 22:27, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Ok, > > > So once we get past the "Why would you ever want to do something dumb > > like that?" and "Bad things will happen..." which I assume means the > > Rails Police will come during the night and kill your cat, how can FMH > > actually get the job done? > > > Seriously guys, give the guy at least a pointer to a real reason not > > to do what he''s trying - don''t just spit dogma. > > > This has worked for me with: > > About your application''s environment > > Ruby version 1.8.7 (powerpc-darwin9) > > RubyGems version 1.3.1 > > Rails version 2.2.2 > > Active Record version 2.2.2 > > Action Pack version 2.2.2 > > Active Resource version 2.2.2 > > Action Mailer version 2.2.2 > > Active Support version 2.2.2 > > Application root /Users/rick/Journeys > > Environment development > > Database adapter postgresql > > > 1) put your needed methods in a module in "lib/your_stuff.rb" where > > your_stuff.rb looks like: > > > module YourStuff > > protected > > def thing1 > > ... > > end > > end > > > 2) add the line "include YourStuff" to the controller for the class > > you want to make thing1 available in: > > > class PagesController < ApplicationController > > include AuthenticatedSystem > > > or, optionally, add it to app/controllers/application.rb to make > > thing1 available everywhere. > > > Now let''s see if there can be some reasonable discussion about why > > this is a "bad idea" and how soon you should expect your cat to die. > > > Rick > > On Feb 7, 5:50 am, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > i did this , because i dont want integrate my users admin with simple > > > users > > > > class Admin < ActiveRecord::BaseWithoutTable > > > column :username , :string > > > column :userpass , :string > > > > def self.authenticate?(username,userpass) > > > admin = Admin.new > > > admin.username = "admin" > > > admin.userpass = "1234" > > > if (admin.username == username && admin.userpass == userpass) > > > true > > > end > > > end > > > end > > > > how to affect this admin to a current_user ? > > > > because if my current_user is an admin user i skip my other problem > > > > On 7 fév, 16:35, Fernando Perez <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > wrote: > > > > > fmh wrote: > > > > > because i have a special controller authentication (an admin model > > > > > without table) and in my model i have a method to authorize some > > > > > action. > > > > > You are trying to break the MVC pattern, only bad things will happen to > > > > you, you certainly have to refactor / rethink your code. > > > > -- > > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
yes i have a user table, now I have included my admins in, with a column UserType and it works very well with restfulauthentication. thanks On 8 fév, 06:52, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Look here for some examples on how to do role based authorization. > > http://www.vaporbase.com/postings/Authorization_in_Rails > > You can also checkout restful-authentication to support the user login > type of accounts. > > http://github.com/technoweenie/restful-authentication/tree/master > > These two work well together. > > On Feb 7, 4:08 pm, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > ok, > > i think i rushed coding this, i now rethinking my code. > > i am not familiar with MVC. > > > On 7 fév, 22:27, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Ok, > > > > So once we get past the "Why would you ever want to do something dumb > > > like that?" and "Bad things will happen..." which I assume means the > > > Rails Police will come during the night and kill your cat, how can FMH > > > actually get the job done? > > > > Seriously guys, give the guy at least a pointer to a real reason not > > > to do what he''s trying - don''t just spit dogma. > > > > This has worked for me with: > > > About your application''s environment > > > Ruby version 1.8.7 (powerpc-darwin9) > > > RubyGems version 1.3.1 > > > Rails version 2.2.2 > > > Active Record version 2.2.2 > > > Action Pack version 2.2.2 > > > Active Resource version 2.2.2 > > > Action Mailer version 2.2.2 > > > Active Support version 2.2.2 > > > Application root /Users/rick/Journeys > > > Environment development > > > Database adapter postgresql > > > > 1) put your needed methods in a module in "lib/your_stuff.rb" where > > > your_stuff.rb looks like: > > > > module YourStuff > > > protected > > > def thing1 > > > ... > > > end > > > end > > > > 2) add the line "include YourStuff" to the controller for the class > > > you want to make thing1 available in: > > > > class PagesController < ApplicationController > > > include AuthenticatedSystem > > > > or, optionally, add it to app/controllers/application.rb to make > > > thing1 available everywhere. > > > > Now let''s see if there can be some reasonable discussion about why > > > this is a "bad idea" and how soon you should expect your cat to die. > > > > Rick > > > On Feb 7, 5:50 am, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > i did this , because i dont want integrate my users admin with simple > > > > users > > > > > class Admin < ActiveRecord::BaseWithoutTable > > > > column :username , :string > > > > column :userpass , :string > > > > > def self.authenticate?(username,userpass) > > > > admin = Admin.new > > > > admin.username = "admin" > > > > admin.userpass = "1234" > > > > if (admin.username == username && admin.userpass == userpass) > > > > true > > > > end > > > > end > > > > end > > > > > how to affect this admin to a current_user ? > > > > > because if my current_user is an admin user i skip my other problem > > > > > On 7 fév, 16:35, Fernando Perez <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > > > wrote: > > > > > > fmh wrote: > > > > > > because i have a special controller authentication (an admin model > > > > > > without table) and in my model i have a method to authorize some > > > > > > action. > > > > > > You are trying to break the MVC pattern, only bad things will happen to > > > > > you, you certainly have to refactor / rethink your code. > > > > > -- > > > > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sometimes we need code accessible from everywhere. Usually models relate to structure of data for storage and business logic. Controllers are for the gluing of interface to model and views are interface related. Ask questions if you get stuck Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/ On 08/02/2009, at 1:08 PM, fmh <helmi.fatnassi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > ok, > i think i rushed coding this, i now rethinking my code. > i am not familiar with MVC. > > > On 7 fév, 22:27, Rick <Richard.T.Ll...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Ok, >> >> So once we get past the "Why would you ever want to do something dumb >> like that?" and "Bad things will happen..." which I assume means the >> Rails Police will come during the night and kill your cat, how can >> FMH >> actually get the job done? >> >> Seriously guys, give the guy at least a pointer to a real reason not >> to do what he''s trying - don''t just spit dogma. >> >> This has worked for me with: >> About your application''s environment >> Ruby version 1.8.7 (powerpc-darwin9) >> RubyGems version 1.3.1 >> Rails version 2.2.2 >> Active Record version 2.2.2 >> Action Pack version 2.2.2 >> Active Resource version 2.2.2 >> Action Mailer version 2.2.2 >> Active Support version 2.2.2 >> Application root /Users/rick/Journeys >> Environment development >> Database adapter postgresql >> >> 1) put your needed methods in a module in "lib/your_stuff.rb" where >> your_stuff.rb looks like: >> >> module YourStuff >> protected >> def thing1 >> ... >> end >> end >> >> 2) add the line "include YourStuff" to the controller for the class >> you want to make thing1 available in: >> >> class PagesController < ApplicationController >> include AuthenticatedSystem >> >> or, optionally, add it to app/controllers/application.rb to make >> thing1 available everywhere. >> >> Now let''s see if there can be some reasonable discussion about why >> this is a "bad idea" and how soon you should expect your cat to die. >> >> Rick >> On Feb 7, 5:50 am, fmh <helmi.fatna...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> i did this , because i dont want integrate my users admin with >>> simple >>> users >> >>> class Admin < ActiveRecord::BaseWithoutTable >>> column :username , :string >>> column :userpass , :string >> >>> def self.authenticate?(username,userpass) >>> admin = Admin.new >>> admin.username = "admin" >>> admin.userpass = "1234" >>> if (admin.username == username && admin.userpass == userpass) >>> true >>> end >>> end >>> end >> >>> how to affect this admin to a current_user ? >> >>> because if my current_user is an admin user i skip my other problem >> >>> On 7 fév, 16:35, Fernando Perez <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> >>> wrote: >> >>>> fmh wrote: >>>>> because i have a special controller authentication (an admin model >>>>> without table) and in my model i have a method to authorize some >>>>> action. >> >>>> You are trying to break the MVC pattern, only bad things will >>>> happen to >>>> you, you certainly have to refactor / rethink your code. >>>> -- >>>> Posted viahttp://www.ruby-forum.com/. > >--~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi FMH, seems you are looking to have a "special case" of a user (a user who is an admin) .... look at this pattern from Martin Fowler and see if it applies... http://martinfowler.com/eaaCatalog/specialCase.html I got to say that within MVC, the Controller should not interfere with the Model as the responsibility of the controller is to select with model and view to use and what to do with the model (not publish anything inside the model). In short MVC can be viewed as split responsibilities (definitions for a lot of these patterns is there http://martinfowler.com/eaaCatalog/ but frankly go get the book, you''ll do yourself a favor): (M)odel: the business logic, data storage (C)ontroller:deciding which model and view are best to handle the user request (V): rendering the model based on decision made by the controller BTW, not tying a model to a table is perfectly acceptable you know. Jean-Marc http://m2i3.com --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---