Delete
Setting
Add New Item
Menu List
Title | Content Type | Order | Action | ||||||
---|---|---|---|---|---|---|---|---|---|
{{kb_content.name}} {{kb_content.name}} | {{setValue(content_types, kb_content.content_type)}} | {{kb_content.sort_order}} | Preview Edit Edit Content | ||||||
{{kb_content.name}} | {{setValue(content_types, kb_content.content_type)}} | {{kb_content.sort_order}} | Preview Edit Edit Content | ||||||
No record |
Step 6: Basic Grails data update
This is complete tutorial to build an application using grails 3.x. There are several parts of tutorial where every part has a specific objective and several steps. So it is a step by step tutorial to build a complete application using grails 3.x.
For update, in the view page
<a class="btn btn-primary" href="{{ route('contact.edit',$contact->id) }}">Edit</a>
And in the controller, update method will be as bellow
public function update(Request $request, $id) {
$rules = array(
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required',
'city' => 'required',
'country' => 'required',
'feedback' => 'required',
);
$validator = Validator::make(Input::all(), $rules);
$this->validate($request, $rules);
if ($validator->fails()) {
return redirect('contact/create')
->withErrors($validator)
->withInput();
} else {
$contact = Contact::find($id);
$contact->first_name = $request->first_name;
$contact->last_name = $request->last_name;
$contact->email = $request->email;
$contact->city = $request->city;
$contact->country = $request->country;
$contact->feedback = $request->feedback;
$contact->zip_code = 'zipcode';
$contact->is_read = '0';
$contact->save();
return redirect('contact')->with('ok', 'Update Success Message ');
}
}