padrino

Padrino model from json data

℡╲_俬逩灬. 提交于 2019-12-01 01:59:35
I have been looking at Padrino for a project I am working on, and it seems a great fit, as I would ideally be wanting to support data being sent and received as json. However I am wondering if there is any automated helper or functionality built in to take data from a post request (or other request) and put that data into the model without having to write custom logic for each model to process the data? In the Blog example they briefly skim over this but just seem to pass the parameter data into the initilizer of their Post model, making me assume that it just magically knows what to do with

Padrino model from json data

若如初见. 提交于 2019-11-30 21:13:44
问题 I have been looking at Padrino for a project I am working on, and it seems a great fit, as I would ideally be wanting to support data being sent and received as json. However I am wondering if there is any automated helper or functionality built in to take data from a post request (or other request) and put that data into the model without having to write custom logic for each model to process the data? In the Blog example they briefly skim over this but just seem to pass the parameter data

How to detect language from URL in Sinatra

随声附和 提交于 2019-11-30 12:20:51
问题 I have a multi-language website and I'm puting the language in the URL like domain.com/en/. When the user doesn't put the language in the URL I want to redirect him to the page in the main language like "domain.com/posts" to "domain.com/en/posts". Is there an easy way to do this with Sinatra? I have more than one hundred routes. So doing this for every route is not a very good option. get "/:locale/posts" do... end get "/posts" do... end Can someone help me? Thanks 回答1: Use a before filter,

How to detect language from URL in Sinatra

谁说我不能喝 提交于 2019-11-30 02:31:48
I have a multi-language website and I'm puting the language in the URL like domain.com/en/. When the user doesn't put the language in the URL I want to redirect him to the page in the main language like "domain.com/posts" to "domain.com/en/posts". Is there an easy way to do this with Sinatra? I have more than one hundred routes. So doing this for every route is not a very good option. get "/:locale/posts" do... end get "/posts" do... end Can someone help me? Thanks Use a before filter, somewhat like this: set :locales, %w[en sv de] set :default_locale, 'en' set :locale_pattern, /^\/?(#{Regexp