我可以向页面添加任务,但只有第一项任务显示在表格中。其余的是作为常规的,未格式化的文本添加。
这是我的home.html.erb
<%= content_for :title, "Home" %>
<h1>Things To Do</h1>
<div class="container" id="table-width">
<% if @tasks.empty? %>
<span>There are no tasks at the moment!</span>
<% else %>
<table class="table">
<thead>
<td>Task</td>
<td>Note</td>
<td>Created At</td>
</thead>
<tbody>
<% @tasks.each do |task| %>
<tr>
<td><%= task.title %></td>
<td><%= task.note %></td>
<td><%= task.created_at.strftime("%A,%B,%Y") %></td>
</tr>
</tbody>
</table>
<% end %>
<% end %>
<%= link_to "New Task", new_path, class: "btn btn-primary" %>
</div>
这是我的new.html.erb
<h1>Write your task here</h1>
<div>
<%= form_for(@task) do |f| %>
<div class="form-group">
<%= f.label :title %>
<%= f.text_field :title, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :note %>
<%= f.text_area :note, class: "form-control" %>
</div>
</div>
<%= f.submit "Create Task", class: "btn btn-primary" %>
<% end %>
答案 0 :(得分:1)
你在function Read-MultiLineInputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText)
{
Add-Type -AssemblyName System.Drawing
Add-Type -AssemblyName System.Windows.Forms
# Create the Label.
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Size(10,10)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.AutoSize = $true
$label.Text = $Message
# Create the TextBox used to capture the user's text.
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Size(10,40)
$textBox.Size = New-Object System.Drawing.Size(575,200)
$textBox.AcceptsReturn = $true
$textBox.AcceptsTab = $false
$textBox.Multiline = $true
$textBox.ScrollBars = 'Both'
$textBox.Text = $Null
# Create the OK button.
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Size(415,250)
$okButton.Size = New-Object System.Drawing.Size(75,25)
$okButton.Text = "OK"
$okButton.Add_Click({ $form.Tag = $textBox.Text; $form.Close() })
# Create the Cancel button.
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Size(510,250)
$cancelButton.Size = New-Object System.Drawing.Size(75,25)
$cancelButton.Text = "Cancel"
$cancelButton.Add_Click({ $form.Tag = $null; $form.Close() })
# Create the form.
$form = New-Object System.Windows.Forms.Form
$form.Text = $WindowTitle
$form.Size = New-Object System.Drawing.Size(610,320)
$form.FormBorderStyle = 'FixedSingle'
$form.StartPosition = "CenterScreen"
$form.AutoSizeMode = 'GrowAndShrink'
$form.Topmost = $True
$form.AcceptButton = $okButton
$form.CancelButton = $cancelButton
$form.ShowInTaskbar = $true
# Add all of the controls to the form.
$form.Controls.Add($label)
$form.Controls.Add($textBox)
$form.Controls.Add($okButton)
$form.Controls.Add($cancelButton)
# Initialize and show the form.
$form.Add_Shown({$form.Activate()})
$form.ShowDialog() > $null # Trash the text of the button that was clicked.
# Return the text that the user entered.
return $form.Tag
}
$multiLineText = $null
$multiLineText = Read-MultiLineInputBoxDialog -Message "Enter computer names (one per line), you can mix school regions, but you can't mix school and corp devices.`r`nSchools require the FQDN e.g. WS000012345.GBN.eq.edu.au Corp only needs the device name." -WindowTitle "Enter Workstation Names"
if (($multiLineText -eq "") -or ($multiLineText -eq $null)) {
Exit
} else {
#Gets the users credentials for their GBN elevated account - this is used throughout the script for authentication
$mycreds = Get-Credential -Credential "GBN\zz-$env:USERNAME" -Message "Please enter your elevated credentials."
if (!(Test-Path -Path "C:\Temp\Computers.txt")) {
New-Item -Path C:\Temp -Name Computers.txt -ItemType File -Force
}
$multiLineText | Out-File -FilePath C:\Temp\Computers.txt -Encoding default -Force
$Computers = Get-Content -Path C:\Temp\Computers.txt
$ComputerTable = @()
foreach ($Computer in $Computers) {
if ($Computer -ne "") {
$Computer = $Computer.ToUpper()
Write-Host -ForegroundColor Cyan "Attempting to connect to " -NoNewline; Write-Host -ForegroundColor Yellow "$Computer"
if (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
Write-Host "Connected successfully, loading data to list..." -ForegroundColor Green
$ComputerList = New-Object -TypeName PSObject
$PCInfo = Get-WmiObject -Class Win32_OperatingSystem -Credential $mycreds -ComputerName $Computer | Select-Object Caption, InstallDate, OSArchitecture, CSName, LastBootUpTime
$ComputerList | Add-Member -MemberType NoteProperty -Name "Computer Name" -Value $Computer.ToUpper() -Force
$ComputerList | Add-Member -MemberType NoteProperty -Name "OS Architecture" -Value $PCInfo.OSArchitecture -Force
$ComputerList | Add-Member -MemberType NoteProperty -Name "Operating System" -Value $PCInfo.Caption -Force
$InstallDateTime = [Management.ManagementDateTimeConverter]::ToDateTime($PCInfo.InstallDate)
$ComputerList | Add-Member -MemberType NoteProperty -Name "Last Re-Imaged" -Value $InstallDateTime -Force
$RebootDateTime = [Management.ManagementDateTimeConverter]::ToDateTime($PCInfo.LastBootUpTime)
$ComputerList | Add-Member -MemberType NoteProperty -Name "Last Restarted" -Value $RebootDateTime -Force
$ComputerTable += $ComputerList
} else {
Write-Host -ForegroundColor Magenta "Your call to $Computer " -NoNewline; Write-Host -ForegroundColor Red "failed" -NoNewline; Write-Host -ForegroundColor Magenta " please check the number and try again."
$ComputerList = New-Object -TypeName PSObject
$ComputerList | Add-Member -MemberType NoteProperty -Name "Computer Name" -Value $Computer -Force
$ComputerList | Add-Member -MemberType NoteProperty -Name "OS Architecture" -Value "No Connection" -Force
$ComputerList | Add-Member -MemberType NoteProperty -Name "Operating System" -Value "No Connection" -Force
$ComputerList | Add-Member -MemberType NoteProperty -Name "Last Re-Imaged" -Value "No Connection" -Force
$ComputerList | Add-Member -MemberType NoteProperty -Name "Last Restarted" -Value "No Connection" -Force
$ComputerTable += $ComputerList
}
}
}
}
$Remotes = $ComputerTable | Sort-Object "Computer Name" | Out-GridView -Title "Computer Info" -OutputMode Multiple
foreach ($Remote in $Remotes) {
$mstscpc = $Remote.'Computer Name'
Start-Process -FilePath "mstsc" -ArgumentList "/v: $mstscpc" -Credential $mycreds
}
if (Test-Path "C:\Temp\Computers.txt") {
Remove-Item -Path "C:\Temp\Computers.txt" -Force
}
开始一个循环,你应该在结束表之前结束循环,如下所示:
<% @tasks.each do |task| %>