Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Using translated fields with formtastic #1

Closed
tonic20 opened this Issue · 3 comments

3 participants

Anton Kopylov Johannes Jörg Schmidt Jacob Atzen
Anton Kopylov

Thank you for nice plugin. I have a problem when I use translated fields in forms with Formtastic.

When I use in views:
= semantic_form_for [:admin, @page] do |f|
= f.inputs do
= f.input :title
= f.buttons

Field title not shown correctly. Workaround is to use in forms proxy field, like title_translated below:

class Post < ActiveRecord::Base
  puret :title

  # proxy for translated field
  def title_translated=(s)
    self.title = s
  end

  def title_translated
    title
  end
end

Then:
= semantic_form_for [:admin, @page] do |f|
= f.inputs do
= f.input :title_translated
= f.buttons

Works fine. How can I use translated fields in forms without such proxy fileds?

Johannes Jörg Schmidt
Owner
jo commented

Seems like this is an issue only with formtastic.

Maybe formtastic looks into the attributes hash of ActiveModel.
Since I do not use that plugin, I won't dig deeper.

But a patch is greatly appreciated!

Greetings
Johannes

Jacob Atzen

Actually this is a problem with plain Rails forms too. I just created a new Rails project to try it out:

rails new purettest
cd purettest
echo "gem 'puret'" >> Gemfile
bundle
rails generate scaffold post title:string description:text
rake db:migrate
rails generate puret:model Post title:string description:text
rake db:migrate
rails server

Go to /posts, create a new post and then try editing it, you will see that the form field is not prefilled.

Johannes Jörg Schmidt jo referenced this issue from a commit
Johannes Jörg Schmidt Merged pull request #5 from jacobat/master.
Fix for issue #1
ec7100e
Johannes Jörg Schmidt
Owner
jo commented

merged. Thank you all.

Johannes Jörg Schmidt jo closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.