Tam nic nie ma. Statyczna treść. Mam lepszy pomysł, podaję pełen algorytm od początku do końca aby to lepiej zobrazować. Wpierw tworzę projekt, jeden kontroler i jeden mailer:
rails myproject
cd myproject
ruby script/controller Home index
ruby script/generate mailer Feedback sent
W config/environment.rb odkomentowałem linijkę
config.frameworks -= [ :action_web_service, :action_mailer ]
W config/environments/development.rb dodałem:
ActionMailer::Base.delivery_method = :test
W config/routes.rb wstawiłem
map.connect '', :controller => "home"
W app/models/feedback.rb mam:
class Feedback < ActionMailer::Base
def sent(sent_at = Time.now)
@subject = 'Feedback#sent'
@body['name'] = "world"
@recipients = 'login@localhost.domain'
@from = 'login@localhost.domain'
@sent_on = sent_at
@headers = {}
end
end
W app/views/feedback/sent.rhtml mam:
Hello <%= @name %>!
W app/controllers/home_controller.rb mam:
class HomeController < ApplicationController
def index
email = Feedback.deliver_sent()
render(:text => "<pre>" + email.encoded + "</pre>" )
end
end
Odpalam webricka: ruby script/server
Kasuję app/public/index.html
Otwieram Firefoksa na http://localhost:3000 i widzę coś takiego:
[code] ActionView::ActionViewError in HomeController#index
No rhtml, rxml, rjs or delegate template found for sent
RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace
c:/opt/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_view/base.rb:387:in find_template_extension_for' c:/opt/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_view/base.rb:323:inpick_template_extension’
c:/opt/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_view/base.rb:238:in render_file' c:/opt/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.3/lib/action_view/base.rb:272:inrender’
c:/opt/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.3/lib/action_mailer/base.rb:363:in render' c:/opt/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.3/lib/action_mailer/base.rb:358:inrender_message’
c:/opt/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.3/lib/action_mailer/base.rb:306:in create!' c:/opt/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.3/lib/action_mailer/base.rb:267:ininitialize’
c:/opt/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in new' c:/opt/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.3/lib/action_mailer/base.rb:227:inmethod_missing’
#{RAILS_ROOT}/app/controllers/home_controller.rb:3:in `index’[/code]