diff --git a/lib/trix/form.rb b/lib/trix/form.rb index 77829be9..5d6605d0 100644 --- a/lib/trix/form.rb +++ b/lib/trix/form.rb @@ -36,7 +36,7 @@ def render options = @options.stringify_keys add_default_name_and_id(options) options['input'] ||= dom_id(object, [options['id'], :trix_input].compact.join('_')) - trix_editor_tag(options.delete('name'), value_before_type_cast(object), options) + trix_editor_tag(options.delete('name'), (options['value'] || value_before_type_cast(object)), options) end end end diff --git a/spec/trix_editor_helper_spec.rb b/spec/trix_editor_helper_spec.rb index a0ef4814..1884e53d 100644 --- a/spec/trix_editor_helper_spec.rb +++ b/spec/trix_editor_helper_spec.rb @@ -9,6 +9,20 @@ assign(:blog, blog) expect(helper.trix_editor(:blog, :text)).to include('trix-editor') end + + it 'uses value from object' do + blog = mock_model('Blog', text: 'my_original_value') + + assign(:blog, blog) + expect(helper.trix_editor(:blog, :text)).to include('my_original_value') + end + + it 'uses a provided value instead of value from object' do + blog = mock_model('Blog', text: 'my_original_value') + + assign(:blog, blog) + expect(helper.trix_editor(:blog, :text, value: "my_provided_value")).to include('my_provided_value') + end end describe '#trix_editor_tag' do