I need a button on the edit page to change attribute value - ruby-on-rails-3

I am new to Rails. In my project, I have a task controller and a tasks table with a column name task_status. When task is saved, the status is set to open. Now, I want to place a mark closed button on the edit view page to set the status to closed.

You can do this in several ways. One way would be to include a check box, named close_task in your form. When this check box is checked and the form is submitted, you check for param[:close_task].
So for example:
def update
if param[:close_task]
#task.status = 'closed'
#task.save
end
...
end

Related

Disallowing textbox editing if a ComboBox in the same Form is not filled (for each row individually) [duplicate]

I am working on an Access 2010 form which where the user can select a record in the form header via a combobox and then build up elements related to the selected record in the detail section of the form. The default view of the form is set to continuous forms.
One of the controls in the detail section of the form is a combobox control. What I want to do is set the enabled property of a textbox on the same row of the form to false based upon a selection from the combobox. The code I am running is:
If Me.cboElementType = "Contract Shrink" Then
Me.txtElementID = ""
Me.txtElementID.Enabled = False
EndIf
This works, but it sets all instances of the textbox (txtElementID) to enabled = false. What I want to have happen is for the txtElementID to have a different enabled setting for each row in the detail section based upon the selection of the combobox cboElementType. So, if cboElementType = "Contract Shrink" on row 1 of the scrolling detail section, the txtElementID.Enabled would be set to false for that row. If cboElementType = "Cost Group" on row 2 of the scrolling detail section, then I'd like txtElementID.Enabled to be False on row 1 of the detail section and txtElementID.Enabled to be True on row 2.
Can anyone confirm or deny that this can be done and, if it can be done, how you would suggest it be accomplished? No matter which way this goes, thanks for help.
You cannot do it through VBA like you did, you need to use Conditional formatting, there you have an option to set the Enabled property.
try in Form_Current() event like
Private Sub Form_Current()
If Me.cboElementType = "Contract Shrink" Then
Me.txtElementID = ""
Me.txtElementID.Enabled = False
EndIf
end sub
I have been searching for days for how to access an individual record on continuous form and I am willing to say it is not possible, but I have a trick that I will share here. I have an investments database, user gets in and writes a proposal and then there is a meeting where either the project is approved (given money) or it is cancelled. However, there are many more states a project can be in, Proposal, Execution, etc. but only Approved/Cancelled can happen at this stage. I created a MockBool field in the Project table. I put that on the continuous form and when the form is closed I run this:
rs_frm=me.recordset
rs_frm.movefirst
while not(rs_frm.eof)
if rs_frm("MockBool") then
rs_frm.edit
rs_frm("ProcessStatus")="Cancelled"
rs_frm("MockBool")=false
rs_frm.update
end if
rs_frm.movenext
wend
I had days of searching and had an epiphany so I thought I would share.

Modify properties for individual controls in the details section of a form in continuous forms view

I have a form with a default view set to continuous forms. I want to set the enabled property of a command button control to disabled for records that have a null value in a specific column.
Short answer, you can't. What you need to do is start the button routine with an IF statement that says if the required control is null then exit sub. That way the button won't do anything if the field has a null value
Try setting the caption in the Detail_Paint event for the form:
cb_SetSpecies.Caption = [Species_Name]
This allows a different value to be set for each record.

Use command button to open selected record on a form without filtering?

I have a continuous form which displays a small amount of data from each record in my table ProjectT (i.e. project name, status) and a command button in the footer which I would like to open the selected record in its expanded single form (where all of the relevant info is displayed).
At first I set this button up using Access's wizard, but realized that Access opens a selected record by filtering the data on the form. The problem with this is that once the expanded form is opened, I want a user to be able to move to other records without having to select to unfilter the results. If I change the button on my continuous form to simply open the expanded single form, is there code I can run to make the form open to the selected record without putting a filter on?
Initially I thought to set the expanded form's (named ProjectF) default value to Forms!ProjectListF!ProjectID (where ProjectListF is the continuous form and ProjectID is the autonumber primary key for ProjectT), but this was not successful, I think because there is more than one ProjectID displayed on ProjectListF.
Another thing to consider is that I have another button on my Main Menu form which opens the ProjectF form in data entry mode to prevent the user inadvertently changing/deleting an existing record when they are trying to add a new one; I have no idea if this might be important when trying to find a solution to my issue.
I'm open to any suggestion--I have an okay handle on SQL, and have delved into a little VBA but am completely self taught. Any ideas? Thanks!
You can open the detailed form with this command:
DoCmd.OpenForm "ProjectF", , , "[ProjectID] = " & Me!ProjectID.Value & ""

Save a user popup selection in a custom Automator Action

Using Xcode 5.* for a cocoa-applescript automator action.
Interface is a a simple popup menu that gets populated using an outlet with:
tell thePopupMenu to removeAllItems()
tell thePopupMenu to addItemsWithTitles_(theList)
When the action is used in a workflow (a Service actually), I want the next time it is run and the action dialog shows up (I will have "Options:Show when run" selected), I want the popup menu to change the selection to the last one that was selected. Right now, the default first item shows, even though last time it was run, the user selected a different item in the popup menu.
My thought was that I need to capture a change in the popup menu with a Sent Action handler, and then set some type of default. I have a working handler:
on thePopupMenuSentAction_(sender)
set popupValue to (popupSelectedValue of my parameters()) as string
-- save this selection somewhere???
end
What's the right way to save this? Do I use User Defaults? My Bindings are currenly all tied through Parameter object/controller. If I should use User Defaults, can someone give example code for setting up User Defaults, and then how to get and set a new value using Cocoa-Applescript?
If I can get the name string of the menu item saved somewhere, I can get the string and then change the selection of the popup menu in the
on opened {}
-- set up the action interface
end
handler which gets called just before the action is displayed each time.
Thanks for any help,
Joe
I did mine a bit differently. I will assume you are referring to what XCode calls a "pop up button" (somewhat misleading). I did not use the parameters at all, although that is probably better for larger projects. Have a look at the code:
script Insert_Picture_into_Powerpoint_Slide_Show
property parent : class "AMBundleAction"
property menuChoices : {"Insert a Beginning", "Insert at End"}
property menuSelection : missing value
if (menuSelection as string) is "missing value"
set menuSelection to 0 as integer -- sets default value
end if
end script
I bound Content Values to File's Owner and under Model Key Path I put menuChoices.
Then you just bind the Selected Index to File's Owner and for the Model Key Path type menuSelection.
Defaults
On the initial run, if the user does not click anything, the menuSelection will be missing value. Because I couldn't find a way around this, I created a conditional which tests for this and sets it to the first choice by default (the one that is shown when you add the action).
When the user selections one of the menu choices, the choice is remembered on sequential runs.

Populating options for drop down list

I have a list that I will have users enter data into, each user needs to select their own location. First I created a drop down field with all the options. The column can be set to force unique values, but this doesnt check until the end when the user goes to save.
Is there a way to check if the users selection is already entered, immediately when the option is selected? (without having to hit save)
OR
Another option I tried was:
Create a separate list with two columns: name and saved. Call it Location_List
Create a view that displays all where saved = no on Location_list
Populate the options on the mainList from a look up the the Location_List. This works.
Add a workflow action to mainList that updates saved = yes on the Location_List. This part doesn't work. Does sharepoint allow this though?
Is there an easier way to accomplish this?
My second option worked, had simply forgotten to update the workflow setting to "Start automatically when item is created" for it to run accordingly.