Mysql Rails 5:如何使用Rails(HTML5)在数据库中插入记录
注:我已经阅读了以下内容: 我使用的是Rails 5 请告诉我如何在数据库中插入记录 我正在使用MYSQL,下面是我的表结构,它是db文件夹中正确的schema.rbMysql Rails 5:如何使用Rails(HTML5)在数据库中插入记录,mysql,ruby-on-rails,ruby,html,ruby-on-rails-3,Mysql,Ruby On Rails,Ruby,Html,Ruby On Rails 3,注:我已经阅读了以下内容: 我使用的是Rails 5 请告诉我如何在数据库中插入记录 我正在使用MYSQL,下面是我的表结构,它是db文件夹中正确的schema.rb ActiveRecord::Schema.define(version: 20161107113839) do `create_table "allusers", force: :cascade, options: "ENGINE=InnoDB `DEFAULT CHARSET=latin1" do |t|` t.
ActiveRecord::Schema.define(version: 20161107113839) do
`create_table "allusers", force: :cascade, options: "ENGINE=InnoDB `DEFAULT CHARSET=latin1" do |t|`
t.string "username", limit: 50, null: false
t.string "email", limit: 50
t.string "password", limit: 50
t.string "likedvideos", limit: 50
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
end
这是我的控制器文件user1\u Controller.rb
class User1Controller < ApplicationController
def user1index
end
您的表单应该如下所示:
<%= form_for @user1 do |u| %>
<%= u.label :username %>:
<%= u.text_field :username %><br />
<%= u.label :email %>:
<%= u.text_field :email %><br />
<%= u.label :password %>:
<%= u.password_field :password %><br />
<%= u.label :liked_videos %>:
<%= u.text_field :liked_videos%><br />
<%= u.submit %>
<% end %>
:
:
:
:
请编辑您的问题并发布实际的错误消息,您对发生的情况的描述有点难以理解。是rails 3还是rails 5?我很困惑,Rails 5 sry纠正了它
<form <% @user1,:action => :new, :method => :post %> >
username: <input type="text" name="username" /><br />
email: <input type="text" name="email" /><br/>
password:<input type="password" name="password" /><br/>
likedvideos: <input type="text" name="likedvideos" /><br/>
</form>
<form <% @user1,:action => :new, :method => :post %> >
home/vaibhav/MusicDirectory/app/views/user1/user1index.html.erb:46: syntax error, unexpected =>, expecting &. or :: or '[' or '.' ...orm '.freeze; @user1 ,:action=> :new ,:method => :post ;@out... ... ^
<%= form_for @user1 do |u| %>
<%= u.label :username %>:
<%= u.text_field :username %><br />
<%= u.label :email %>:
<%= u.text_field :email %><br />
<%= u.label :password %>:
<%= u.password_field :password %><br />
<%= u.label :liked_videos %>:
<%= u.text_field :liked_videos%><br />
<%= u.submit %>
<% end %>