Dango
Dango

Reputation: 159

Rails Modify Scaffold Form

Using rails 5.0.0 for building a simple timecard module for a web application. My question is how do I go about modifying a form which is automatically being rendered by rails scaffold

rails g scaffold Timesheet user:string clock:string time:datetime 

=== new.html.erb file ===

<%= render 'form', timesheet: @timesheet %>

In the user string want to add <%= current_user.email %> and in clock string want to add a drop-down? What is the best way to do this? Already have database table in place etc...

Illustration below

enter image description here

Thanks in advance!

Upvotes: 0

Views: 1078

Answers (3)

Nesha Zoric
Nesha Zoric

Reputation: 6620

When you run

$rails generate scaffold <name>

you will auto-generate a ready to use controller, model, and views with a full CRUD (Create, Read, Update, Delete) web interface.

You can modify each of the CRUD operations to your liking, in your case timesheets view which is located in app/views/timesheets/.

Upvotes: 0

SignorHarry
SignorHarry

Reputation: 44

Ok, in: app/views/timesheets - you should find your form. If you change something in form, check it with your 'new' merhod (or with last method - if you didn't change/add anything: this method will get your params) in controller.

Upvotes: 0

ollpu
ollpu

Reputation: 1873

The form is in an automatically generated partial, located in app/views/timesheets/_form.html.erb.

Upvotes: 1

Related Questions