I have a question about localization, I am trying to do multilingual routes, using I18n.
I am using translations in my project, but, I would like to do this
get "/#{I18n.t('routes.kategorie')}" do ...
but, loading crashes on
! Unable to load application: Mustermann::CompileError: capture name can't be empty: "/translation missing: cs.routes.kategorie"
bundler: failed to load command: puma (/usr/local/bin/puma)
Mustermann::CompileError: capture name can't be empty: "/translation missing: cs.routes.kategorie"
but when I start my app (without that route) with pry, I can use this translation
[3] pry(#<Osadababa::App>)> t('routes.kategorie')
=> "kategorie"
[4] pry(#<Osadababa::App>)> I18n.locale = :en
=> :en
[5] pry(#<Osadababa::App>)> t('routes.kategorie')
=> "category"
For both languages.
I am working in toplevel app.
Please any suggestions?
Thanks
I will answer myself, better way is to handle multiple routes, by Padrino or Sinatra style, I am trying to do according the documentation, but still not working
Related
I built an api only rails app, but since i'm using a 3rd party email service, I need to be able to render the email template into a string to pass it to the mailing service wrapper gem. So far any attempt to render templates into a string returns an empty string, and i suspect it is because the application is configured to be API only. Ho do I add support to rendering templates into a string?
If this is not the case, please let me know. I'm using postmark mail service. postmark-rails gem, which integrates into standard rails mailers didn't work at all, and plain postmark gem (which uses postmark API instead of postmark SMTP server) works fine, but now my problem is producing the proper html for the email.
this is what I'm trying:
html = render_to_string(
partial: "transfer_mailer/transfer.html.erb",
locals: {
:#body => #body,
:#campaign => #campaign,
:#chat => #chat
}
)
but it returns empty string.
My setup involves Rails 5.0.1, ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux], Sidekiq 4.2.7, and in production im using nginx/1.10.2 and Phusion Passenger 5.1.1. Production environment is deployed in an azure virtual machine, and I added both inbound and outbound rules for allowing traffic through ports 25, 465, 2525, and 587.
Any help would be really appreciated.
Looking at the docs for render_to_string, it looks like the path doesn't need to include .html.erb, so maybe removing that will fix it.
You can see here for some example code:
In your case, it would be:
render_to_string(
partial: '/transfer_mailer/transfer',
locals: {
:#body => #body,
:#campaign => #campaign,
:#chat => #chat
},
layout: false
)
Also make sure the partial filename starts with an underscore, even though you don't include it with render_to_string or render calls.
There is the other way to use render_to_string for resolving your issue. Please see the code below.
#body = XXX
#campaign = YYY
#chat = ZZZ
html = render_to_string(
file: 'transfer_mailer/transfer.html.erb'
)
Hope it helps.
I am trying to implement doorkeeper into my Rails App. My App consists of 2 mountable engines. Api and CoreApi.
constraints :subdomain => 'api' do
mount Api::Engine => '/'
end
constraints :subdomain => 'core.api' do
mount CoreApi::Engine => '/'
end
I want to use Doorkeeper in the CoreApi Engine to protect those endpoints with OAuth. I have included the Doorkeeper gem in my gemspec for that engine. I have also set the symbol in the initializer.
CoreApi::Doorkeeper = ::Doorkeeper
Everything is working except when I try to visit the applications index path for doorkeeper. I ran rake routes and the paths for the CoreApi engine list all the doorkeeper paths. The issue is
undefined local variable or method `new_oauth_application_path'
its referring to the url helper on line 11 of doorkeeper-1.0.0/app/views/doorkeeper/applications/index.html.erb
I can't figure out why this is not resolving. I assume its because doorkeeper is a rails mountable engine and I am trying to mount it inside a rails mountable engine.
Add to first line of config/initializers/doorkeeper.rb:
Doorkeeper::ApplicationController.send(:include, CoreApi::Engine.routes.url_helpers)
I am using sessions in my Facebook Canvas Application using Sinatra and Rack.
The error that occurs in Facebook Canvas is:
NoMethodError - undefined method `session' for #<Hash:0xa3ed0a0>:
/home/apoorv/.rvm/gems/ruby-1.9.2-p320/gems/sinatra-1.3.2/lib/sinatra/base.rb:170:in `session'
The problem is surely with Rack because when I run my application as follows:
ruby application.rb -p 3000
it does not display any error. I have tried installing rack version: 1.3.6 and 1.4.1, but the error persists.
I have also tried using the following code instead of enable :sessions
use Rack::Session::Cookie, :key => 'rack.session',
:domain => 'static.ak.facebook.com',
:path => '/',
:secret => 'change_me'
Do I need to upgrade/degrade to lower version of Rack or add some piece of Code to make this thing work?
edited
Also before coming across this issue I had an issue integrating my application in Facebook Canvas which was resolved by adding this line in config.ru:
set :protection, :except => [:remote_token, :frame_options]
Using env['rack.session'] instead of session[] in the POST request recieved from Facebook solved this issue. Hope this helps to solve such problems
Though it has not fully resolved complications because, now adding a redirect to code in the same POST callback displays: undefined method secure? error.
I have not been able to solve this issue, though what I did was to avoid the redirect thing and instead add a functionality to the controller to handle different requests.
I have been working with php for more than 5 years. Lately I have worked in rubyonrails. I have done a few projects in this very nice framework. What I like best from rails and ruby: they both promote automate test and there are so many rich libs. Rspec and TestUnit are very easy to learn comparing to PhpUnit.
I have to develop a very big project in the next coming month. I am a big fan in cakephp but I realize that cakephp will not meet my project requirement. I am a quick learner. After reading doc from Kohana official website, I will use Kohana for this project.
After having done some search on Kohana, I still have a few topics to concern about
The test module is lack of doc. I am not clear how to test model, controller, functional test. Could anyone provide me ideas, tutorials, examples, resources ?
The application environment is not quite clear. Sorry because I am pretty family with rubyonrails . I feel like environment in rails make more sense to me. I can have one gem in a specific environment. for example I have rspec gem (for automate test ) for test environment only and I have unicorn gem for production only. For those who are new to ruby, gem is something similar to "module" in kohana. Could anyone tell me how to tell kohana to just load "unittest" in test environment only ? because I don't want to load unittest in production env.
In Rails there is an app console mode called rails console. with rails console we can interact with models via console mode . Is there anything similar to this in Kohana ?
I can answer only 2 of your questions, still better then nothing ;)
AD2. You can set Kohana::$environment variable based on the .htaccess (setenv and getenv) / $_SERVER setting:
if (Arr::get($_SERVER, 'SERVER_NAME') !== 'localhost')
{
// We are live!
Kohana::$environment = Kohana::PRODUCTION;
// Turn off notices and strict errors
error_reporting(E_ALL ^ E_NOTICE ^ E_STRICT);
}
else
{
Kohana::$environment = Kohana::DEVELOPMENT;
error_reporting(E_ALL | E_STRICT);
}
Then you can setup Kohana::init like this:
Kohana::init(array(
'base_url' => '/',
'caching' => Kohana::$environment === Kohana::PRODUCTION,
'profile' => Kohana::$environment !== Kohana::PRODUCTION,
'index_file' => FALSE,
'errors' => TRUE
));
so your production application will have caching enabled and profiling disabled.
For the modules it's pretty much the same:
if (Kohana::$environment !== Kohana::PRODUCTION)
{
Kohana::modules(array(
'unittest' => MODPATH . 'unittest',
));
}
AD3. Sorry for being laconic - no, there isn't one.
I have a question regarding using rack-mount with Sinatra. I've got two classic-style Sinatra apps. Let's call one App defined in app.rb and the other API defined in api.rb.
I would like it so that api.rb handles all routes beginning with '/api' and app.rb handles all other requests including the root ('/').
How would I set this up with rack-mount? Or is there a better solution than that?
I think you'll prefer Rack::URLMap - it will probably look something like this:
run Rack::URLMap.new("/" => App.new,
"/api" => Api.new)
That should go in your config.ru file.
I had a similar issue and I am not very familiar with Rack. I could not figure out what to do based on the answers above. My final solution was to have the following in config.ru.
This works perfectly for me.
# Main Ramaze site
map "/" do
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
require ::File.expand_path('../app', __FILE__)
Ramaze.start(:root => __DIR__, :started => true)
run Ramaze
end
# Sinatra & Grape API
map "/api" do
use Rack::Static, :urls => ["/stylesheets", "/images", "/javascripts"], :root => "public"
use Rack::Session::Cookie
run Rack::Cascade.new([
MySinatraApp::Application,
MySinatraApp::API])
end
In config.ru you could also take advantage of Sinatra's middleware feature. If you have several Sinatra apps, each with its own routes, and want to run them simultaneously, you can arrange them in the order you want them found, e.g.
# config.ru
...
use MyAppA
use MyAppB
use MyAppC
run MyAppD
I had the same problem once and so I came up with this template: sinatra-rspec-bundler-template which is layed out for multiple apps.
It may have more features than you need but it should help you when you need something "a bit more" complex.