Sinatra 1.2.6 / Haml 3.1.2 and Pony
I am getting "wrong number of arguments error (0 for 1)" which points to
sinatra/base.rb
def haml(template, options={}, locals={})
render :haml, template, options, locals
end
I am sending :html_body => (haml :html_email) to Pony
Any help would be very much appreciated!
M.
Your code seems to work in Sinatra 1.2.6, Haml 3.1.3 and Pony 1.3.
Although I would use haml(:test) instead of (haml :test)
test.rb:
require 'rubygems'
require 'sinatra'
require 'pony'
require 'haml'
set :views, Proc.new { root }
get '/send' do
options = {
:to => 'user#gmail.com',
:from => 'user#gmail.com',
:subject => 'Test',
:body => 'Test Text',
:html_body => (haml :test),
:via => :smtp,
:via_options => {
:address => 'smtp.gmail.com',
:port => 587,
:enable_starttls_auto => true,
:user_name => 'login',
:password => 'password',
:authentication => :plain,
:domain => 'HELO'
}
}
Pony.mail(options)
end
test.haml:
!!!
%html
%head
%meta{ :content => "text/html; charset=utf-8", :"http-equiv" => "Content-Type" }
%title Test
%body
%h1 Test
%p Test content
Related
I always getting an error when sending an email. I already openned the open_ssl on php.ini . Currently i am using "guzzlehttp/guzzle": "~4.0" for the mail.
Here's my mail.php settings :
'driver' => 'smtp',
'host' => 'smtp.gmail.org',
'port' => 587,
'from' => array('address' => 'tokotonight456#gmail.com', 'name' => 'tonight'),
'encryption' => 'tls',
'username' => '', //i already set the username + pass correctly
'password' => '',
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
Mail::send('mail', array('firstname'=>'budi'), function($message) {
$message->to('tokotonight456#gmail.com','lukas aa')->subject('Welcome to the Laravel 4 Auth App!');
});
Use Mandrill driver instead of smtp. Laravel ships with it.
in app/config/mail.php
change this line
'driver' => 'mandrill',
go to https://mandrillapp.com/settings
sign up and create an an api key
create an app/config/services.php configuration fileand add below configurations and mandrill api key
return array(
'mailgun' => array(
'domain' => '',
'secret' => '',
),
'mandrill' => array(
'secret' => 'enter your mandrill api key here',
),
'stripe' => array(
'model' => 'User',
'secret' => '',
),
);
So I am debugging some code that someone else wrote and it utilises the cakephp cake email thing. I have never used it before and have never written an email function before either.
When the function executes it outputs cakes standard: "Error: An Internal Error Has Occurred"
as well as this line:
SMTP Error: 535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257 h66sm5396348yhb.7 - gsmtp
The code is here:
public function newAppEmail($email_addr, $password) {
$Email = new CakeEmail();
$Email->config('default');
$Email->sender(array('polarontest#gmail.com' => 'Polaron'));
$Email->from(array('polarontest#gmail.com' => 'Polaron'));
$Email->to($email_addr);
$Email->subject('Eligibility Check');
$Email->template('newapp');
$Email->emailFormat('text');
$Email->viewVars(array('name' => $this->request->data['Applicant']['first_name'], 'email' => $this->request->data['Applicant']['email'], 'password' => $password));
$Email->attachments(array(
'Polaron - PL Passport - Info Pack - 2013.pdf' => array(
'file' => APP . 'documents/Email_attachments/Polaron - PL Passport - Info Pack - 2013.pdf',
'mimetype' => 'pdf'),
));
$Email->send();
}
and this is the config file:
<?php
class EmailConfig {
public $default = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'company name'),
'sender' => array('email#email.com' => 'company name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
public $fast = array(
'transport' => 'Smtp',
'from' => array('email#email.com' => 'Test Mail name sender'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'email#email.com',
'password' => 'password');
}
Can anyone shed some light on what might be wrong and where I should look to fix it?
Well, SMTP Error 535 means that authentication fails, which is easy to find out.
The exception is thrown because of that. So get the right credentials and try again, this is not an issue of the php code but your credentials.
If your login / password is correct, test the configuration:
public $smtp = array(
'transport' => 'Smtp',
'from' => array('email#gmail.com' => 'Name'),
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'timeout' => 30,
'username' => 'email#gmail.com',
'password' => '**********',
'client' => null,
'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
I'm trying to integrate FedEx with my application. I created a test account.
When I send RateRequest I got a response Authentication Failed (code is 1000).
I use v10 of Fedex Rate service. For SOAP I use Savon ruby gem.
Here is code I use:
require 'rubygems'
require 'savon'
TEST_URL = 'https://wsbeta.fedex.com:443/web-services/rate'
client = Savon::Client.new do
wsdl.document = File.expand_path("../rate_wsdl.xml", __FILE__)
wsdl.endpoint = TEST_URL
end
client.request "RateRequest" do
soap.body = {
'WebAuthenticationDetail' => {'Key' => KEY, 'Password' => PASSWORD},
'ClientDetail' => {'AccountNumber' => ACCOUNT_NUMBER, 'MeterNumber' => METER_NUMBER},
'RequestedShipment' => {
'PackagingType' => 'FODEX_BOX',
'Shipper' =>
{'Address' => {'PostalCode' => '90210', 'CountryCode' => 'US', 'Residential' => 'true'}
},
'Recipient' =>
{'Address' => {'PostalCode' => 'KIP 1J1', 'CountryCode' => 'CA', 'Residential' => 'true'}
},
'RateRequestTypes' => 'ACCOUNT',
'PackageCount' => '1',
'RequestedPackages' => {
'Weight' => {'Units' => 'LB', 'Value' => '7.5'},
'Dimensions' => {'Length' => '15', 'Width' => '10', 'Height' => '5', 'Units' => 'IN'}
}
#'LabelSpecification' => ''
}
}
end
I googled a lot about it. Some people had the same problem. People say it can be caused because of lack of permission of address validation, but I can't find how I can disable it if so.
I am sure that all credentials are OK (account number, meter number, key, password).
Also I tried "https://wsbeta.fedex.com:443/web-service" for endpoint url as well.
Figured out of was wrong. I sent invalid SOAP request. Thanks to SOAPUI tool, it helped me to validate my request.
I'm having problems submitting my form now that I've converted from erb to haml in a simple sinatra app.
new.haml
%form{ :action => "/new", :method => "post"}
%fieldset
%ol
%li
%label{:for => "username"} Name:
%input{:type => "text", :username => "name", :class => "text"}
%input{:type => "submit", :value => "Send", :class => "button"}
In my app.rb
get '/new' do
haml :new
end
post '/new' do
radcheck = Radcheck.new(:username => params[:username])
if radcheck.save
redirect '/'
else
"Hello World"
end
end
each time I get the Hello World statement appear. My logs show nothing interesting.
Any ideas? Worked just fine with erb??
This is what I've tested
get '/new' do
haml :new
end
post '/new' do
#radcheck = Radcheck.new(:username => params[:username])
username = params[:username]
if username
username
else
"Hello World"
end
end
and new.haml
%form{ :action => "/new", :method => "post"}
%fieldset
%ol
%li
%label{:for => "username"} Name:
%input{:type => "text", :name => "username", :class => "text"}
%input{:type => "submit", :value => "Send", :class => "button"}
And it works as expected. So for some reason radcheck.save is returning false, but that has nothing to do with haml. (But notice that I have corrected input with :name => "username")
I'm trying to create a nested resource with a url scheme along the lines of: "http://example.com/username/...".
What I currently have is this:
ActionController::Routing::Routes.draw do |map|
map.home '/', :controller => 'home'
map.resource :session
map.resources :users, :has_many => :nodes
#map.user '/:id', :controller => 'users', :action => 'show', :has_many => :nodes
map.resources :nodes, :belongs_to => :user
end
This results in URLs like:
http://example.local/users/username
http://example.local/users/username/nodes
How to avoid the "users" prefix is beyond me. Passing a "as: => ''" option to map.resources doesn't work and it seems named routes don't support the ":has_many" or ":belongs_to" options.
Commenting out the "map.resources :users" and uncommmenting the "map.user" line after it seems to work… until you reach a nested resource. Then it spits out the following error:
undefined method `user_nodes_path' for #<ActionView::Base:0x1052c8d18>
I know this problem has come up plenty of times before and is always met with "Why would you want to do that?" responses. Frankly, Twitter does it, Facebook does it, and I want to do it too! ;-D
As for the common criticism of how to avoid usernames from conflicting built-in paths, I've set my minimum username length to 6 characters and plan to make all built-in root-level paths segments paths 5 characters or shorter (i.e. "/opt/..." for options, "/in/..." for session log-in, etc.).
As noted in this question:
Default segment name in rails resources routing
You should be able to use this plugin:
http://github.com/caring/default_routing
Alternatively, you could specify them manually with something like
map.users '/users', :controller => 'users', :action => 'index',
:conditions => { :method => :get }
map.connect '/users', :controller => 'users', :action => 'create',
:conditions => { :method => :post }
map.user '/:id', :controller => 'users', :action => 'show',
:conditions => { :method => :get }
map.edit_user '/:id/edit', :controller => 'users', :action => 'edit',
:conditions => { :method => :get }
map.new_user '/users/new', :controller => 'users', :action => 'new',
:conditions => { :method => :get }
map.connect '/:id', :controller => 'users', :action => 'update',
:conditions => { :method => :put }
map.connect '/:id', :controller => 'users', :action => 'destroy',
:conditions => { :method => :delete }
map.resources :nodes, :path_prefix => '/:user_id', :name_prefix => 'user_'
# to generate user_nodes_path and user_node_path(#node) routes
That or something like it should give you what you want from map.resources.
map.resources doesn't work and it seems named routes don't support the ":has_many" or ":belongs_to" options.
Named routes supports has_many, which is used to add another resource level to the URL path. For example
map.resources :users, :has_many => :nodes
generates all the users_path and user_nodes_path routes like /users, /users/:id, /users/:id/nodes and /users/:id/nodes/:id. It's identical to
map.resources :users do |user|
user.resources :nodes
end
Commenting out the "map.resources :users" and uncommmenting the "map.user" line after it seems to work… until you reach a nested resource. Then it spits out the following error:
undefined method `user_nodes_path' for #<ActionView::Base:0x1052c8d18>
That's because map.resources :users, :has_many => :nodes generates these routes. Only one named route is generated by map.user '/:id', :controller => 'users', :action => 'show' and that's user_path.
See my answer in this related question
Basically, you can pass :path => '' as an option to negate the identifying segment (Tested in Rails 3 only) Just be aware that this may clash with other routing patterns, so be careful where and how you place it.