class TeachingPlace < ActiveRecord::Base
  belongs_to :department
  belongs_to :lecturer
  belongs_to :position
  has_many :charge_cards, :dependent => :destroy

  validates_presence_of :department, :lecturer

  def name
    lecturer.name + ' (' + department.name + ')'
  end
end

no authorized_for_delete method

2010/9/17 Sergio Cambra .:: entreCables S.L. ::. <[email protected]>:
> On Viernes, 17 de Septiembre de 2010 12:18:37 Andrey Voronkov escribió:
>> config.actions.exclude :delete
>>
>> this string did the trick! but I do not understand why?
>
> Don't you have a authorized_for_delete method in TeachingPlace model?
>
>>
>> 2010/9/17 Sergio Cambra .:: entreCables S.L. ::. <[email protected]>:
>> > On Viernes, 17 de Septiembre de 2010 11:51:55 Andrey Voronkov escribió:
>> >> update, delete, show
>> >
>> > Try to remove those actions, do queries disappear?
>> >
>> >> 2010/9/17 Sergio Cambra .:: entreCables S.L. ::.
> <[email protected]>:
>> >> > On Viernes, 17 de Septiembre de 2010 11:36:16 Andrey Voronkov escribió:
>> >> >> no I have not. No any authentication system (as cancan for example)
>> >> >> authentication based on a namespaces. In each namespace there is
>> >> >> BaseController that has :authenticate_dept_head! (it is an example
>> >> >> for dept_head namespace)
>> >> >
>> >> > What action links are displayed for each row?
>> >> >
>> >> >> 2010/9/17 Sergio Cambra .:: entreCables S.L. ::.
>> >
>> > <[email protected]>:
>> >> >> > On Viernes, 17 de Septiembre de 2010 11:22:23 Andrey Voronkov
> escribió:
>> >> >> >> can a conditions_for_collection makes department to load each
>> >> >> >> time? but it has no sense.
>> >> >> >
>> >> >> > conditions_for_collection is only called to bulid the list query,
>> >> >> > it isn't called for each row.
>> >> >> >
>> >> >> > I can see query is issued in list_actions partial, so probably some
>> >> >> > security method checks current_user.department. Have you defined
>> >> >> > some action_authorized method in your controller, or
>> >> >> > authorized_for_action method in your model?
>> >> >> >
>> >> >> >> Here is listing from the top of action processing if it helps. As
>> >> >> >> an autientication system I use devise. And dept_head user belongs
>> >> >> >> to department. But I think it should'n be checked on each row.
>> >> >> >>
>> >> >> >> Processing DeptHead::TeachingPlacesController#index (for 127.0.0.1
>> >> >> >> at 2010-09-17 19:09:40) [GET]
>> >> >> >>   DeptHead Load (3.5ms)   SELECT * FROM "users" WHERE
>> >> >> >> ("users"."id" = 4) AND ( ("users"."type" = 'DeptHead' ) ) LIMIT 1
>> >> >> >>   Department Load (43.8ms)   SELECT * FROM "departments" WHERE
>> >> >> >> ("departments"."id" = 1)
>> >> >> >>   SQL (99.3ms)   SELECT count(DISTINCT "teaching_places".id) AS
>> >> >> >> count_all FROM "teaching_places" LEFT OUTER JOIN "lecturers" ON
>> >> >> >> "lecturers".id = "teaching_places".lecturer_id LEFT OUTER JOIN
>> >> >> >> "positions" ON "positions".id = "teaching_places".position_id
>> >> >> >> WHERE (("teaching_places"."department_id" = 1))
>> >> >> >>   TeachingPlace Load (4.7ms)   SELECT "teaching_places".* FROM
>> >> >> >> "teaching_places" WHERE (("teaching_places"."department_id" = 1))
>> >> >> >> ORDER BY "teaching_places"."id" ASC LIMIT 30 OFFSET 0
>> >> >> >>   Lecturer Load (3.7ms)   SELECT * FROM "lecturers" WHERE
>> >> >> >> ("lecturers"."id" IN
>> >> >> >> (11,6,7,12,8,13,9,14,15,16,17,1,2,18,19,3,10,4,5))
>> >> >> >>   Position Load (1.7ms)   SELECT * FROM "positions" WHERE
>> >> >> >> ("positions"."id" IN (1,2,3))
>> >> >> >> Rendering template within layouts/application
>> >> >> >> Rendering list
>> >> >> >> Rendered _list_header (26.4ms)
>> >> >> >> Rendered _list_column_headings (35.9ms)
>> >> >> >> Rendered _messages (2.4ms)
>> >> >> >> Rendered _list_messages (186.4ms)
>> >> >> >> Rendered _list_record_columns (12.6ms)
>> >> >> >>   CACHE (0.0ms)   SELECT * FROM "departments" WHERE
>> >> >> >> ("departments"."id" = 1) Rendered _list_actions (75.7ms)
>> >> >> >> Rendered _list_record (121.6ms)
>> >> >> >> Rendered _list_record_columns (4.4ms)
>> >> >> >>   CACHE (0.0ms)   SELECT * FROM "departments" WHERE
>> >> >> >> ("departments"."id" = 1)
>> >> >> >>
>> >> >> >> ...
>> >> >> >>
>> >> >> >> 2010/9/17 Sergio Cambra .:: entreCables S.L. ::.
>> >> >
>> >> > <[email protected]>:
>> >> >> >> > On Viernes, 17 de Septiembre de 2010 01:29:30 Andrey Voronkov
>> >
>> > escribió:
>> >> >> >> >> This is an example of N+1 error in my case:
>> >> >> >> >>
>> >> >> >> >> ...
>> >> >> >> >>
>> >> >> >> >> CACHE (0.0ms)   SELECT * FROM "departments" WHERE
>> >> >> >> >> ("departments"."id" = 1) Rendered _list_actions (26.8ms)
>> >> >> >> >> Rendered _list_record (34.9ms)
>> >> >> >> >> Rendered _list_record_columns (4.4ms)
>> >> >> >> >>   CACHE (0.0ms)   SELECT * FROM "departments" WHERE
>> >> >> >> >> ("departments"."id" = 1) Rendered _list_actions (26.9ms)
>> >> >> >> >> Rendered _list_record (33.4ms)
>> >> >> >> >> Rendered _list_record_columns (4.3ms)
>> >> >> >> >>   CACHE (0.0ms)   SELECT * FROM "departments" WHERE
>> >> >> >> >> ("departments"."id" = 1)
>> >> >> >> >
>> >> >> >> > If you are excluding department column, why is department
>> >> >> >> > loaded? Is it used in some override? In a security check? Anyway
>> >> >> >> > you can override active_scaffold_includes:
>> >> >> >> >    def active_scaffold_includes
>> >> >> >> >     �...@active_scaffold_includes ||= [:department]
>> >> >> >> >    end
>> >> >> >> >
>> >> >> >> >> ...
>> >> >> >> >>
>> >> >> >> >> 2010/9/17 Andrey Voronkov <[email protected]>:
>> >> >> >> >> > I have model TeachingPlace that belongs to Department and to
>> >> >> >> >> > the Lecturer models and has table field called position. I
>> >> >> >> >> > want to rid off N+1 SQL requests. There is no N+1 if
>> >> >> >> >> > config.columns = [:lecturer, :department, :position]
>> >> >> >> >> >
>> >> >> >> >> > Person who works with this interface is a department agent so
>> >> >> >> >> > I have this two methods:
>> >> >> >> >> >
>> >> >> >> >> > protected
>> >> >> >> >> >
>> >> >> >> >> >  def before_create_save(record)
>> >> >> >> >> >    if dept = current_dept_head.department
>> >> >> >> >> >      record.department_id = dept.id
>> >> >> >> >> >    end
>> >> >> >> >> >  end
>> >> >> >> >> >
>> >> >> >> >> >  def conditions_for_collection
>> >> >> >> >> >    if @dept ||= current_dept_head.department
>> >> >> >> >> >      {:department_id => @dept.id}
>> >> >> >> >> >    else
>> >> >> >> >> >      {:department_id => nil}
>> >> >> >> >> >    end
>> >> >> >> >> >  end
>> >> >> >> >> >
>> >> >> >> >> > As you can guess I do not need to display department field in
>> >> >> >> >> > list or anywhere in this interface because the user knows
>> >> >> >> >> > what department he represents. But this:
>> >> >> >> >> > config.list.columns.exclude :department
>> >> >> >> >> > causes N+1 error. Is there any kind of descision of my
>> >> >> >> >> > trouble?
>> >> >> >> >
>> >> >> >> > --
>> >> >> >> > Sergio Cambra .:: entreCables S.L. ::.
>> >> >> >> > Mariana Pineda 23, 50.018 Zaragoza
>> >> >> >> > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>> >> >> >> >
>> >> >> >> > --
>> >> >> >> > You received this message because you are subscribed to the
>> >> >> >> > Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To
>> >> >> >> > post to this group, send email to
>> >> >> >> > [email protected]. To unsubscribe from this group,
>> >> >> >> > send email to
>> >> >> >> > [email protected]. For more options,
>> >> >> >> > visit this group at
>> >> >> >> > http://groups.google.com/group/activescaffold?hl=en.
>> >> >> >
>> >> >> > --
>> >> >> > Sergio Cambra .:: entreCables S.L. ::.
>> >> >> > Mariana Pineda 23, 50.018 Zaragoza
>> >> >> > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>> >> >> >
>> >> >> > --
>> >> >> > You received this message because you are subscribed to the Google
>> >> >> > Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to
>> >> >> > this group, send email to [email protected]. To
>> >> >> > unsubscribe from this group, send email to
>> >> >> > [email protected]. For more options,
>> >> >> > visit this group at
>> >> >> > http://groups.google.com/group/activescaffold?hl=en.
>> >> >
>> >> > --
>> >> > Sergio Cambra .:: entreCables S.L. ::.
>> >> > Mariana Pineda 23, 50.018 Zaragoza
>> >> > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>> >> >
>> >> > --
>> >> > You received this message because you are subscribed to the Google
>> >> > Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this
>> >> > group, send email to [email protected]. To unsubscribe
>> >> > from this group, send email to
>> >> > [email protected]. For more options, visit
>> >> > this group at
>> >> > http://groups.google.com/group/activescaffold?hl=en.
>> >
>> > --
>> > Sergio Cambra .:: entreCables S.L. ::.
>> > Mariana Pineda 23, 50.018 Zaragoza
>> > T) 902 021 404 F) 976 52 98 07 E) [email protected]
>> >
>> > --
>> > You received this message because you are subscribed to the Google Groups
>> > "ActiveScaffold : Ruby on Rails plugin" group. To post to this group,
>> > send email to [email protected]. To unsubscribe from this
>> > group, send email to [email protected]. For
>> > more options, visit this group at
>> > http://groups.google.com/group/activescaffold?hl=en.
>
> --
> Sergio Cambra .:: entreCables S.L. ::.
> Mariana Pineda 23, 50.018 Zaragoza
> T) 902 021 404 F) 976 52 98 07 E) [email protected]
>
> --
> You received this message because you are subscribed to the Google Groups 
> "ActiveScaffold : Ruby on Rails plugin" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/activescaffold?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/activescaffold?hl=en.

Reply via email to