0

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!

Dango
  • 149
  • 2
  • 14

3 Answers3

1

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

ollpu
  • 1,783
  • 15
  • 26
  • In the controller, you can do: `Timesheet.new(user: current_user.email)` (in the new-action in place of `Timesheet.new`), to preset the value. The user can still change it in the form, though. – ollpu Aug 30 '16 at 19:02
0

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.

0

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/.

Nesha Zoric
  • 6,218
  • 42
  • 34