开发者

Make a controller

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.


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


If you just want to link your email, you don't necessarily need a controller for that. You can just do:

link_to 'Click to email me', 'mailto: me@example.com'

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜