UPDATE
Solution to assign lang in controller:
def create
@article = Article.new(article_params)
@article.lang = params[:title].blank? ? "de" : "eng"
if @article.save
redirect_to @article
else
render 'new'
end
end
Or, if you prefer, you could use javascript/jquery to get the value of :title and then assign the correct value to :lang before submitting your form.
Snippet:
$('#my-button').on('click', function() {
event.preventDefault();
var title = $('#title').val();
if(title == "") {
$('#lang').val("de");
} else {
$('#lang').val("eng");
}
// change to $('#my-form').submit();
alert($('#lang').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="my-form">
title: <input type="text"name="title" id="title"/><br>
title_de: <input type="text" name="title_de" id="title_de"/><br>
<input type="hidden" id="lang" name="lang" />
<input type="submit" id="my-button" />
</form>