Assuming the ErrorType class has some sort of name-ish attribute, this
controller action should work:
def index
hobo_index ErrorLog.apply_scopes(:error_type_is => params[:error_type])
end
apply_scopes takes care of the 'nevermind the filter if the value is blank'
issue. Here's an equivalent formulation without apply_scope, to make it clearer
what's happening:
def index
if params[:error_type].blank?
proxy = ErrorLog
else
error_type = ErrorType.find_by_name(params[:error_type])
proxy = ErrorLog.scoped(:conditions => ['error_type_id = ?', error_type.id])
end
hobo_index proxy
end
--Matt Jones
On Dec 6, 2010, at 5:00 PM, Tuishimi wrote:
> Well, so I need to perhaps add a method that would take the parameter
> and use it in a "find" and return the error_logs based on that? Or is
> there a better, more accepted way to manage filters? I have to admit,
> I've looked at the cookbook and am having a hard time applying it. :/
>
> On Dec 6, 2:40 pm, Matt Jones <[email protected]> wrote:
>> On Dec 6, 2010, at 3:36 PM, Tuishimi wrote:
>>
>>> Struggling. ErrorLogs is the class, it belongs_to error_type. I want
>>> the index page for ErrorLog (error_logs) to have a filter that can
>>> limit selection to error_types...
>>
>>> My filter-menu happily shows the appropriate error_types... here is
>>> my code.
>>
>>> def index
>>> finder = params[:error_type] ?
>>> ErrorLog.send(params[:error_type]) : ErrorLog
>>> hobo_index finder
>>> end
>>
>> One note on this: don't do this. Consider what might happen, for instance,
>> if somebody passed 'delete_all' in params[:error_type]. Uh-oh!
>>
>>
>>
>>
>>
>>> <collection: replace>
>>> <table-plus fields="this, error_type, detail">
>>> <empty-message:>No errors found!</empty-message:>
>>> <prepend-header:>
>>> <div class="filter">
>>> Display by Error Type:
>>> <filter-menu param-name="error_type"
>>> options="&ErrorType.all"/>
>>> </div>
>>> </prepend-header:>
>>> </table-plus>
>>> </collection:>
>>
>>> ...
>>
>>> I get an error saying:
>>
>>> NoMethodError in Error logsController#index
>>
>>> undefined method `ERROR_TYPE_1' for #<Class:0x4b919723>
>>
>>> ...where ERROR_TYPE_1 is one of the errors in the dropdown...
>>
>>> I've tried following the online stuff I could find for this. I am
>>> sure I am missing something simple.
>>
>> Note that the generated HTML is going to send back whatever the ErrorType
>> models yield from to_s; you may need to munge the value into the correct
>> format if that doesn't match the scopes defined on ErrorLog.
>>
>> --Matt Jones- Hide quoted text -
>>
>> - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" 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/hobousers?hl=en.
>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" 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/hobousers?hl=en.