如何在 Rails 中创建基本提交表单并写入数据库?
我正在尝试构建一个微型应用程序,用户在其中粘贴链接,单击提交,该链接将添加到数据库中,并且还会显示(从数据库调用)在提交表单下方的列表中。
我创建了一个 Rails 应用程序,在 index.html.erb 文件中我有这样的内容:
<%= form_tag("/search", :method => "get") do %>
<%= label_tag(:q, "Please Paste your Link here") %> <br /> <br />
<%= text_field_tag(:q) %>
<%= submit_tag("Submit") %>
<% end %>
该代码已从教程站点重新调整用途,因此第一行中的 /search 目标不会指向我的应用程序中真实的任何位置。
我试图简单地让此提交进入我创建的数据库,运行 bundle exec rake db:create
不知道下一步该怎么做才能将我粘贴的链接记录到数据库中。
I'm trying to build a micro-app where a user pastes a link, clicks submit, the link is added to the database and is also shown (called from the database) in a list below the submission form.
I've created a Rails app and in the index.html.erb file I have this:
<%= form_tag("/search", :method => "get") do %>
<%= label_tag(:q, "Please Paste your Link here") %> <br /> <br />
<%= text_field_tag(:q) %>
<%= submit_tag("Submit") %>
<% end %>
That code has been repurposed from a tutorial site so the /search destination in the first line doesn't point to anywhere real in my app.
I'm trying to simply get this submission to go into my database that I created running bundle exec rake db:create
Not sure what to do next to get the link I paste to enter be logged in the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在完成您想要做的事情之前,您需要完成一些学习曲线。您的应用程序至少需要一个控制器、模型和一些路由才能使该表单正常工作。
我建议看一些介绍视频,它们应该能够涵盖您需要的大部分/全部内容。
这里有一些免费视频:http://rubyonrails.org/screencasts
Rails for zombies 也是交互式学习 Rails 的好方法 http://railsforzombies.org/
如果您不是视频人员然后有大量可用的书籍涵盖了您需要的所有信息。
希望这有帮助。
There's a little bit of a learning curve that you'll need to achieve before you can complete what you're trying to do. Your application will require a controller, model and some routes at least in order to get that form working correctly.
I'd suggest taking a look at some introduction videos that should be able to cover most/all of what you require.
There are some videos available here for free: http://rubyonrails.org/screencasts
Rails for zombies is also a great way to learn rails interactively http://railsforzombies.org/
If you're not a video person then there are plenty of books available which cover all the info you need.
Hope this helps.