On 25 Mar 2011, at 16:47, John Merlino <li...@ruby-forum.com> wrote:

> Frederick Cheung wrote in post #988949:
>> On Mar 23, 8:52pm, John Merlino <li...@ruby-forum.com> wrote:
>>> 
>>> 
>        if 
> params[:controller].singularize.capitalize.constantize.method_defined? 
> :viewable

Why not just controller.respond_to? :viewable ?

Fred



>          table_str += "\t\t\t<th>"
>          table_str += "View"
>          table_str += "</th>\n"
>        end
> 
>      table_str += "\t\t</tr>\n"
>    table_str += "\t</thead>\n"
>    table_str += "\t<tbody>\n"
>      collection.each do |col|
>        table_str += "\t\t<tr>\n"
>          fields.each do |name|
>            table_str += "\t\t\t<td>\n"
>              table_str += col[name].to_s
>            table_str += "\t\t\t</td>\n"
>        end
>        if 
> params[:controller].singularize.capitalize.constantize.method_defined? 
> :viewable
>          table_str += "\t\t\t<td>\n"
>            table_str += link_to 'View', :action => 'show', :id => 
> col.id
>          table_str += "\t\t\t</td>\n"
>        end
> 
>        table_str += "\t\t</tr>\n"
>      end
>    table_str += "\t</tbody>\n"
>  table_str += "</table>\n"
>  table_str.html_safe
>     end
> 
> It works but I dont like that I am checking whether a model has the 
> method "viewable" just to display a link to a detail view in the table. 
> Is there a better way to determine if the current controller's table 
> should contain a view or not?
> 
> Thanks for response.
> 
> -- 
> 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@googlegroups.com.
> To unsubscribe from this group, send email to 
> rubyonrails-talk+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
> 

-- 
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to