[Cmsplugin-users] hello and question about sortable_list
Antonio Tapiador del Dujo
atapiador at dit.upm.es
Fri Sep 5 02:50:03 EDT 2008
El Thursday 04 September 2008 11:05:08 David Tapiador del Dujo escribió:
> First at all, hello! that is my first email! :D
Hi David! Welcome to the list!
> I just use the last version of cms_plugin for a managment aplication in a
> Rails 2.1.0. environment
>
> My question is a about sortable_list and if it is possible to arrange in it
> differents field more dinamically...
>
> I mean... i have to views that need a sortable list about the model
> MacrosAction. One, is the own list in index action, but other go inside of
> an other show action that belongs to the Macro model, those has_many:
> macros_actions.
>
> The second list should render differents fields than the first. For
> example, i'm not interested in know who is the macro owner of this
> macro_action in the second case, but yes in one.
>
> Maybe one choice is to create a new option in sortable_list in which you
> can set which act_as_sortable list are you chosing, por example:
>
> #
> class MacrosAction < ActiveRecord::Base
>
> acts_as_sortable :columns => [ { :name => "My MacroAction Name",
>
> :content => proc { |helper,
> : macros_action|
>
> macros_action.name }},
>
> :created_at ],
> :
> :list_name => "index"
>
> acts_as_sortable :columns => [ { :name => "My *Macro* Name",
>
> :content => proc { |helper,
> : macros_action|
>
> macros_action.macro.name }},
>
> :created_at ],
> :
> :list_name => "inside_macro"
>
> end
>
> Then, in view, it can be rendered as:
>
> #
> <%= sortable_list @macros_actions, MacroAction, :append => "&q=#{
> params[:q]}", :list => "index"%>
>
> or just in second context.
>
> #
> <%= sortable_list @macros_actions, MacroAction, :append => "&q=#{
> params[:q]}", :list => "inside_macro" %>
>
>
> It is only a suggestion, maybe it can be done by other way...
What about defining all the columns you need in the Model, and choosing which ones you'll display in the Helper, using their :id?
Example:
class MacrosAction < ActiveRecord::Base
acts_as_sortable :columns => [ { :id => :macro_action_name,
:name => "My MacroAction Name",
:content => proc { |helper, macros_action|
macros_action.name }},
{ :id => :macro_name,
:name => "My *Macro* Name",
:content => proc { |helper, macros_action|
macros_action.macro.name }},
{ :id => :created_at,
:content => :created_at }
end
Index:
<%= sortable_list @macros_actions, MacroAction, :append => "&q=#{params[:q]}", :columns => [ :macro_action_name, :created_at ] %>
Show:
<%= sortable_list @macros_actions, MacroAction, :append => "&q=#{params[:q]}", :columns => [ :macro_action, :created_at ] %>
More information about the Cmsplugin-users
mailing list