Action Link Usage

21 views
Skip to first unread message

redbros

unread,
Jul 6, 2009, 2:16:08 AM7/6/09
to ActiveScaffold : Ruby on Rails plugin
Hi,

I'm new to ActiveScaffold. Just got it setup and trying to customize
it now. I need some help with the usage of the Action Link. I want to
add a link to a column for each of my record. According to this
http://activescaffold.com/docs/api-action-link I could do that by

config.columns[:name].link

Doesn't seem to create a link on the table in each row. Also, how do I
add restful feature to the link (e.g.: Need to
add :action, :controller, :id

I'm on ActiveScaffold version for rails 2.1

Any help is very much appreciated!!!

-Dave

Sergio Cambra .:: entreCables S.L. ::.

unread,
Jul 6, 2009, 11:35:22 AM7/6/09
to actives...@googlegroups.com
On Lunes, 6 de Julio de 2009 08:16:08 redbros escribió:
> Hi,
>
> I'm new to ActiveScaffold. Just got it setup and trying to customize
> it now. I need some help with the usage of the Action Link. I want to
> add a link to a column for each of my record. According to this
> http://activescaffold.com/docs/api-action-link I could do that by
>
> config.columns[:name].link

To set a link in a column:
config.columns[:name].set_link 'action_name', :controller => 'controller_name'
You can add more options, look at api: action link
http://wiki.github.com/activescaffold/active_scaffold/api-action-link

To add a link at right (next to edit, delete and show links):
config.action_links.add 'action_name', :type => 'record', ...

>
> Doesn't seem to create a link on the table in each row. Also, how do I
> add restful feature to the link (e.g.: Need to
> add :action, :controller, :id
>
> I'm on ActiveScaffold version for rails 2.1
>
> Any help is very much appreciated!!!
>
> -Dave
>
>
--
Sergio Cambra .:: entreCables S.L. ::.
Mariana Pineda 23, 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) ser...@entrecables.com

redbros

unread,
Jul 6, 2009, 12:12:29 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
Thanks Sergio for jumping in.

I did use "set_link" like you indicated but got error while rendering
the page. Any ideas?

Showing vendor/plugins/active_scaffold/frontends/default/views/
_list_record.rhtml where line #14 raised:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.name

Extracted source (around line #14):

11: <% column_value = get_column_value(record, column) -%>
12:
13: <td class="<%= column_class(column, column_value) %>" >
14: <%= render_list_column(column_value, column, record) %>
15: </td>
16: <% end -%>
17: <% if active_scaffold_config.action_links.any? {|link| link.type
== :record } -%>

Trace of template inclusion: /vendor/plugins/active_scaffold/frontends/
default/views/_list.rhtml, /vendor/plugins/active_scaffold/frontends/
default/views/list.rhtml

vendor/plugins/active_scaffold/lib/active_scaffold/helpers/
list_column_helpers.rb:69:in `render_list_column'
vendor/plugins/active_scaffold/frontends/default/views/
_list_record.rhtml:14:in
`_run_erb_47vendor47plugins47active_scaffold47frontends47default47views47_list_record46rhtml'
vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/
action_columns.rb:69:in `each'
vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/
action_columns.rb:56:in `each'
......

On Jul 6, 10:35 am, "Sergio Cambra .:: entreCables S.L. ::."
<ser...@entrecables.com> wrote:
> On Lunes, 6 de Julio de 2009 08:16:08 redbros escribió:
>
> > Hi,
>
> > I'm new to ActiveScaffold. Just got it setup and trying to customize
> > it now. I need some help with the usage of the Action Link. I want to
> > add a link to a column for each of my record. According to this
> >http://activescaffold.com/docs/api-action-linkI could do that by
>
> > config.columns[:name].link
>
> To set a link in a column:
> config.columns[:name].set_link 'action_name', :controller => 'controller_name'
> You can add more options, look at api: action linkhttp://wiki.github.com/activescaffold/active_scaffold/api-action-link

Kenny Ortmann

unread,
Jul 6, 2009, 12:15:49 PM7/6/09
to actives...@googlegroups.com
Would you paste your controllers code as well please?

redbros

unread,
Jul 6, 2009, 12:25:20 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
Here's my controller code. :product is my model:

class StoreController < ApplicationController

active_scaffold :product do |config|
config.columns =
[:code, :name, :make, :model, :year, :equipment_type, :price]
config.actions.exclude :create, :delete, :show, :update
config.columns[:name].set_link 'show', controller => 'store'
end

@sort_type = ''
@max_per_page = 50
@tag_names = nil

# Our simple store index
def index
@title = "Store"
@tags = Tag.find_alpha
@tag_names = nil
@viewing_tags = nil


@products = Product.paginate(
:order => 'name ASC',
:conditions => Product::CONDITIONS_AVAILABLE,
:page => params[:page],
:per_page => @max_per_page
)
end

def search
@search_term = params[:search_term]
@title = "Search Results for: #{@search_term}"
@products = Product.paginate(
:order => 'name ASC',
:conditions => ["(name LIKE ? OR code = ? OR model LIKE ?) AND #
{Product::CONDITIONS_AVAILABLE}", "%#{@search_term}%", @search_term,
@search_term],
:page => params[:page],
:per_page => @max_per_page
)
# If only one product comes back, take em directly to it.
if @products.size == 1
redirect_to :action => 'show', :id => @products[0].code and
return
else
render :action => 'index'
end
end

def show
@product = Product.find_by_code(params[:id])
if !@product
flash[:notice] = "Sorry, we couldn't find the product you were
looking for"
redirect_to :action => 'index' and return false
end
@title = @product.name
@images = @product.images.find(:all)
@default_image = @images[0]
@variations = @product.variations.find(
:all,
:order => 'name ASC',
:conditions => 'quantity > 0'
)
end

end

On Jul 6, 11:15 am, Kenny Ortmann <kenny.ortm...@gmail.com> wrote:
> Would you paste your controllers code as well please?
>
> > > >http://activescaffold.com/docs/api-action-linkIcould do that by

Kenny Ortmann

unread,
Jul 6, 2009, 12:33:48 PM7/6/09
to actives...@googlegroups.com
Sorry I should have been more specific, I only wanted you to post the active scaffold part of your controller,


  active_scaffold :product do |config|
   config.columns = [:code, :name, :make, :model, :year, :equipment_type, :price]
   config.actions.exclude :create, :delete, :show, :update
   config.columns[:name].set_link 'show', controller => 'store'
 end

I noticed this,    config.columns[:name].set_link 'show', controller => 'store'

try putting :controller => 'store'

~Kenny

redbros

unread,
Jul 6, 2009, 12:39:12 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
Sorry, that was my bad when pasting the code. I was trying out
different stuffs before replying. I did have ":controller => 'show'"
Does it have to do with how I do association in the model?

It shows fine without trying to put links on the rows.
> > > > >http://activescaffold.com/docs/api-action-linkIcoulddo that by

Kenny Ortmann

unread,
Jul 6, 2009, 12:54:36 PM7/6/09
to actives...@googlegroups.com
try just using
config.columns[:name].set_link 'show'

redbros

unread,
Jul 6, 2009, 1:10:07 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
:( Still the same error.

On Jul 6, 11:54 am, Kenny Ortmann <kenny.ortm...@gmail.com> wrote:
> try just using
> config.columns[:name].set_link 'show'
>
> > > > > > >http://activescaffold.com/docs/api-action-linkIcoulddothat by

Kenny Ortmann

unread,
Jul 6, 2009, 1:56:46 PM7/6/09
to actives...@googlegroups.com
try

config.columns[:name].clear_link

config.columns[:name].set_link 'show', :controller => "store"

redbros

unread,
Jul 6, 2009, 2:09:51 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
Still getting the error.
Does this feature work for you?
Thanks for your help so far though......I really appreciate it!

On Jul 6, 12:56 pm, Kenny Ortmann <kenny.ortm...@gmail.com> wrote:
> try
>
> config.columns[:name].clear_link
> config.columns[:name].set_link 'show', :controller => "store"
>

Kenny Ortmann

unread,
Jul 6, 2009, 3:34:13 PM7/6/09
to actives...@googlegroups.com
Can you update your version of active scaffold, I just pused a change to the version for rails-2.1

~kenny

redbros

unread,
Jul 6, 2009, 4:29:46 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
I re-installed my active scaffold but got this while trying to start
the web server. I got this before too, but I forgot what I had to do
to get it to work. I re-installed with

./script/plugin install git://github.com/activescaffold/active_scaffold.git
-r rails-2.1

It looks like it's not downloading the right code branch?

=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails 2.1.0 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
Exiting
/Users/David/Project/Development/RailsDev/svn/pttrading/vendor/plugins/
active_scaffold/init.rb:5:in `evaluate_init_rb': This version of
ActiveScaffold requires Rails 2.3 or higher. Please use an earlier
version. (RuntimeError)
from ./script/../config/../vendor/rails/railties/lib/rails/
plugin.rb:95:in `evaluate_init_rb'
from /Users/David/Project/Development/RailsDev/svn/pttrading/
vendor/rails/activesupport/lib/active_support/core_ext/kernel/
reporting.rb:11:in `silence_warnings'
from ./script/../config/../vendor/rails/railties/lib/rails/
plugin.rb:91:in `evaluate_init_rb'
from ./script/../config/../vendor/rails/railties/lib/rails/
plugin.rb:44:in `load'
from /Users/David/Project/Development/RailsDev/svn/pttrading/
config/../vendor/plugins/engines/lib/engines/plugin.rb:77:in `load'
from ./script/../config/../vendor/rails/railties/lib/rails/
plugin/loader.rb:33:in `load_plugins'
from ./script/../config/../vendor/rails/railties/lib/rails/
plugin/loader.rb:32:in `each'
from ./script/../config/../vendor/rails/railties/lib/rails/
plugin/loader.rb:32:in `load_plugins'
... 31 levels...
from /Users/David/Project/Development/RailsDev/svn/pttrading/
vendor/rails/railties/lib/commands/server.rb:39
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `gem_original_require'
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:31:in `require'
from script/server:3

On Jul 6, 2:34 pm, Kenny Ortmann <kenny.ortm...@gmail.com> wrote:
> Can you update your version of active scaffold, I just pused a change to the
> version for rails-2.1
>
> ~kenny
>

redbros

unread,
Jul 6, 2009, 4:52:23 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
I fixed the "script/server" start problem. Just downloaded the source
using git instead of the plugin install.

Now, back to the original problem. It still errors out, but now in a
different line in the "list_column_helpers.rb"

Showing vendor/plugins/active_scaffold/frontends/default/views/
_list_record.rhtml where line #14 raised:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.authorized_for?

Extracted source (around line #14):

11: <% column_value = get_column_value(record, column) -%>
12:
13: <td class="<%= column_class(column, column_value) %>" >
14: <%= render_list_column(column_value, column, record) %>
15: </td>
16: <% end -%>
17: <% if active_scaffold_config.action_links.any? {|link| link.type
== :record } -%>

Trace of template inclusion: /vendor/plugins/active_scaffold/frontends/
default/views/_list.rhtml, /vendor/plugins/active_scaffold/frontends/
default/views/list.rhtml

RAILS_ROOT: /Users/David/Project/Development/RailsDev/svn/pttrading
Application Trace | Framework Trace | Full Trace

vendor/plugins/active_scaffold/lib/active_scaffold/helpers/
list_column_helpers.rb:70:in `render_list_column'
vendor/plugins/active_scaffold/frontends/default/views/
_list_record.rhtml:14:in
`_run_erb_47vendor47plugins47active_scaffold47frontends47default47views47_list_record46rhtml'
vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/
action_columns.rb:69:in `each'


On Jul 6, 3:29 pm, redbros <david.chin.c...@gmail.com> wrote:
> I re-installed my active scaffold but got this while trying to start
> the web server. I got this before too, but I forgot what I had to do
> to get it to work. I re-installed with
>
> ./script/plugin install git://github.com/activescaffold/active_scaffold.git
> -r rails-2.1
>
> It looks like it's not downloading the right code branch?
>
> => Booting Mongrel (use 'script/server webrick' to force WEBrick)
> => Rails 2.1.0 application starting onhttp://0.0.0.0:3000
> ...
>
> read more »

redbros

unread,
Jul 6, 2009, 5:03:38 PM7/6/09
to ActiveScaffold : Ruby on Rails plugin
I tried changing line 70 in "list_column_helpers.rb" to

authorized = associated.authorized_for?(:action => link.crud_type) if
associated

So that it doesn't error out if "associated" is nil.
Now it works! But, my link doesn't seem to be "clickable" - i viewed
the page source and saw that it rendered a "disabled" link?

I must be missing something, but looks like I'm getting closer. If you
see anything I don't, please let me know :)

Thanks!
Dave
> ...
>
> read more »

Kenny Ortmann

unread,
Jul 6, 2009, 5:05:46 PM7/6/09
to actives...@googlegroups.com
I think I fixed that problem as well, update again and try it please.

Kenny Ortmann

unread,
Jul 6, 2009, 5:36:23 PM7/6/09
to actives...@googlegroups.com
Yeah I updated the version for rails-2.1 a second time so if you update your codebase again it should work

the line should read

authorized = associated ? associated.authorized_for?(:action => link.crud_type) : record.authorized_for(:action => link.crud_type)

~Kenny

redbros

unread,
Jul 7, 2009, 2:03:56 PM7/7/09
to ActiveScaffold : Ruby on Rails plugin
Looks like something else is missing on your code change. It's giving
this error:

Showing vendor/plugins/active_scaffold/frontends/default/views/
_list_record.rhtml where line #14 raised:
undefined method `authorized_for' for #<Product:0x312f9f0>
Extracted source (around line #14):
11: <% column_value = get_column_value(record, column) -%>
12:
13: <td class="<%= column_class(column, column_value) %>" >
14: <%= render_list_column(column_value, column, record) %>
15: </td>
16: <% end -%>
17: <% if active_scaffold_config.action_links.any? {|link| link.type
== :record } -%>
Trace of template inclusion: /vendor/plugins/active_scaffold/frontends/
default/views/_list.rhtml, /vendor/plugins/active_scaffold/frontends/
default/views/list.rhtml
RAILS_ROOT: /Users/David/Project/Development/RailsDev/svn/pttrading
Application Trace | Framework Trace | Full Trace
vendor/rails/activerecord/lib/active_record/attribute_methods.rb:
256:in `method_missing'
vendor/plugins/active_scaffold/lib/active_scaffold/helpers/
list_column_helpers.rb:70:in `render_list_column'
vendor/plugins/active_scaffold/frontends/default/views/
_list_record.rhtml:14:in
`_run_erb_47vendor47plugins47active_scaffold47frontends47default47views47_list_record46rhtml'
vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/
action_columns.rb:69:in `each'

On Jul 6, 4:36 pm, Kenny Ortmann <kenny.ortm...@gmail.com> wrote:
> Yeah I updated the version for rails-2.1 a second time so if you update your
> codebase again it should work
>
> the line should read
>
> authorized = associated ? associated.authorized_for?(:action =>
> link.crud_type) : record.authorized_for(:action => link.crud_type)
>
> ~Kenny
>
> ...
>
> read more »

Kenny Ortmann

unread,
Jul 7, 2009, 3:40:45 PM7/7/09
to actives...@googlegroups.com
The error isn't on the code change.  I believe ActiveScaffold should have added the authorized_for?(*args) method to your Product class.  It does this so that you can put a method

def authorized_for_show?
  if authorized
    return true
  else
    return false
  end
end

which would allow you to restrict access to the show action on a per record basis.  I still couldn't reproduce the problem so I can't look into it deeper.

Try putting this method in your Product class
def authorized_for?(*args)
  @authorized_for_delegatee ||= self.new
  @authorized_for_delegatee.authorized_for?(*args)
end
 and let me know if that works.

~Kenny
Reply all
Reply to author
Forward
0 new messages