制作一个控制器
我有一个用 html/css 制作的网站。我刚刚开始学习 RubyOnRails,我想将我的 URL 链接转换为控制器。所以我做了一个新的控制器,现在我不知道如何继续。我有一个电子邮件按钮,我为 mail_controller.rb 创建了一个控制器,并希望它链接到我的电子邮件地址。
I've this website I made in html/css. And I'm just starting to learn RubyOnRails and I'd like to turn my URL links into controllers. So I made a new controller, and now I don't know how to go forward. I got an email button which I made a controller for mail_controller.rb and want it to link to my email adress.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不仅需要控制器,还需要其路由。
确保您在 config/routes.rb 文件中有一个将您想要的 url 与您创建的控制器进行映射的路由。
也许您可能想查看指南: http://guides.rubyonrails.org/getting_started.html
You need not only the controller, but also the routes for that.
Make sure you have on the
config/routes.rb
file a route mapping the url you want with the controller you made.Perhaps you may want to take a look at the guides: http://guides.rubyonrails.org/getting_started.html
如果您只想链接电子邮件,则不一定需要控制器。您可以这样做:
它将打开用户的邮件客户端以将邮件发送到给定的电子邮件地址。如果您想使用操作邮件程序,那么我建议您阅读:
http://guides.rubyonrails.org/action_mailer_basics .html
If you just want to link your email, you don't necessarily need a controller for that. You can just do:
and it will open the user's mail client to sent a mail to the given email address. If you wanted to use action mailer, then I suggest you read:
http://guides.rubyonrails.org/action_mailer_basics.html
您似乎刚刚开始使用 Rails。我强烈建议你买一本书来开始。对于 Rails 新手来说,Agile Rails 可能是一个非常好的选择。
它将帮助您更好地理解 MVC 模型在 Rails 中如何工作,如何设置控制器、模型、路由等。此时,当您开始时,您需要更好地了解 Rails 的整体工作原理,最好的方法是阅读一本书,或者甚至更好,按照 Sebastian Martinez 的说法,阅读在线指南。
You seem like you are just starting with Rails. I would highly recommend that you get a book to start with that. Agile Rails is probably a very good choice for newcomers in Rails.
It will help you better understand how the MVC model works in Rails, how to set up controllers, models, routes and more. At this point when you start, you need to have a better understand of how Rails works overall and the best way to do that is by reading a book or, maybe even better, do as Sebastian Martinez says, read the online guides.