Creating a Rails partial that is resource-agnostic - ruby-on-rails-3

This question is related to my previous question, Creating a Rails partial that is model-agnostic.
I am trying to create a Rails partial that is given a variable, say, seasonal_type, and does several different operations, such as querying a resource, and accessing instance variables, based on the value of the variable.
To be more concrete: I have the two models SafetyTest and TeamDue, which belong to Student. In one particular case in this partial, I need to call either
#student.safety_tests or #student.team_dues. I would like to pass the variable seasonal_type to the partial and like that determine which of the two is executed. How would I be able to do this? The value of the variable could be whatever is most convenient, such as a symbol (:safety_test) or a model (SafetyTest).
There is also another part to this question. In my controller, I precaculcated some instance variables for SafetyTest and TeamDue, such as #valid_safety_test and #valid_team_due. In my partial, how can I use either of these two instance variables, based on the value of seasonal_type? Or should I just calculate these values inside the partial, even though that would be against the MVC structure?
Any help would be much appreciated.

Here is the answer:
In my controller, I created an array with the models of both seasonal types: [SafetyTest, TeamDue]
Then I iterated over this array, and used the model to query all the information that I needed from the database. I put that information into an array and passed it on to the view with an instance variable. So this array also has two items, one for SafetyTest and one for TeamDue.
Then the partial iterates through this array and renders the view necessary.

Related

Choosing id one by one from a variable in jmeter

I want to delete mappings in DB using DataService.
For this purpose
I run search query for all ids in first thread group.
Using this method I put my Ids into the property.
Now property has view like that b69243ee6e9efdf66114200dc93881ac,b69243ee6e9efdf66114200dc90f5ba4,b69243ee6e9efdf66114200dc90e2184
I want to all delete mapping using this Ids from property one by one.
For this purpose I need run BeanShell Pre-Processor and choose first id and put it into variable. Please, help me with this script.
I believe ForEach Controller is the solution. But in my experience, I use regular expression extractor to grab the values and put it in one variable then loop it using ForEach Controller. I think these step will help you:
Add Regular Expression Extractor to grab the ids.
Make sure you fill field "Match No" with negative number (i.e. -1). Put the extracted value into one variable (i.e. IdVar. Fill Reference Name with IdVar). This step will grab all matched ids and put it into IdVar variable.
Then Add ForEach Controller to process each ids from IdVar variable.
For the details, just download this sample and try to run it.
I hope this will help you. :-)

How to insert data into objects iterated by Yii CActiveDataProvider

I have a strange request and I'm not sure there is a better way other than simply brute force, but I have a CActiveDataProvider being rendered and virtual properties of the underlying Model are being used.
I would like to be able to pass extra information to that Model to filter the calculations in those virtual properties.
For example, assume there is a virtual property method getCreated_Widget_Count() that returns the number of widgets that the entity (let's say it is a widget maker) has created it its lifetime.
I would like to be able to filter the count to a specific date range.
So I want to be Create a CActiveDataProvider and use it in a CListView to display each of the elements, and the view is accessing property created_widget_count. But I want it to, sometimes, limit the result to a number based on an date range.
The obvious thing to do is iterate over the entire data set first and set the range to filter in each object, but I was hoping that there was a way to pass information to the CActiveDataProvider that could get into each constructor so that could be done while they are being built.
Any ideas?

How to access a Field in a Dynpro i Added via the Dict in the PAI?

I have the following question:
I have a dypro and added via the layout builder a dict delement: mara-matnr
Now I see it in my element list:
Now I wanted to know, how to access the value of the matnr in my PAI which looks like this:
MODULE user_command_1000 INPUT.
" HOW TO ACCESS THE VALUE OF MATNR HERE?
ENDMODULE.
I have to guess what you did to get that far, and I’d strongly recommend not to continue along that road. What I’d rather do is
create a new dictionary structure (not a transparent table!) that contains the screen fields you need
use the TABLES statement with the structure to declare a global variable in your program or function pool top include
place the fields of the structure on the screen, just like you did with the MARA fields in your example
use the fields of your global variable in your coding
The way you prepared the screen, you would have to add a global variable named MARA with the structure of the transparent table MARA, probably using the statement TABLES mara. While this is perfectly possible, it’s also really dangerous - you could end up changing the database contents inadvertedly, especially since you seem to be rather new to the system.

A proper way to reduce provided data set in UITableViewController

I am provided a reference to a NSArray that contains data items. In my Custom View controller that acts as a data source for the table view, I interpret each item and present it as a cell.
So far so good.
Now there is a requirement from my colleagues to implement a filter, that will be based on values of one of the item's properties.
This property has enumerated values (4 of them). So when I apply the filter, i should see only items that match the particular value.
My question is how should I approach this filtering of that data.
1) Should I set the _data private variable to point to the original data source, and then override the "data" property getter to take into account the filtering?
2) Should I generate a separate filteredData array inside my controller?
3) Some other approach?
NOTE> coredata+fetched resultscontr. is out of the question. The number of items never will be more then 150-200.
I would go with the second choice. Having a filteredDatasource is more convenient. This way, you are able to know , not only the cells you should display, but also how many they are etc. Moreover, if in the future you want to sort them and use sections, you will be far more flexible.
For example when you implement the method – tableView:numberOfRowsInSection: which is called many times internally using the filtered data source you do not have to traverse through the array's objects many times so as to see which of them should pass the filter. You just return [filteredDatasource count]. This is more efficient.
In the apps I work on we have a array of all items and a copy which is the one the datasource refers to. When a filter is applied it replaces the copy but is based on the original array. So I guess #2.

Looping through a dataset - object-oriented approach

The problem is as follows, a group of users (~50k) must be filtered from a DB, four fields for each user must be saved into a variable, then a second process will take each user and proceed to enable some licences into another system/platform. Both processes will be developed into the same application.
My first attempt was basically a query looping through the users but I wonder if thinking in objects is a better approach.
I was thinking in a structure inside an object to hold the 4 parameters, then pass each user object to the other object however considering the amount of data I'm not sure if this is fine.
Thanks,
ps. newbie using vb.net and framework 3.5
if you read the dataset directly from DB then table columns will have the type of original table in DB,,, If some the filed's its bool, int string then no need to create objects from that dataset and you can make your filters using Data view and then pass this data view to the other process...