jejacks0n / mercury

Mercury Editor: The Rails WYSIWYG editor that allows embedding full page editing capabilities directly inline.
http://jejacks0n.github.com/mercury
Other
2.63k stars 531 forks source link

Can't add select in options form #22

Closed jocubeit closed 12 years ago

jocubeit commented 12 years ago

I tried the following:

<% @options = params[:options] || {} %>
<%= semantic_form_for 'options', { :html => { :style => 'width: 600px' } } do |f| %>
  <div class="mercury-modal-pane-container">
    <div class="mercury-modal-pane">
      <%= f.inputs 'Options' do %>
        <%= f.input :campaign_id, :required => true, :as => :select, 
                    :collection => { "Google Adwords" => 1, "Facebook Ad" => 2, "No Referrer" => 3 },
                    :input_html => { :value => @options[:campaign_id] || 1, :allow_blank => true } %> 

      <% end %>
    </div>
  </div>
  <div class="mercury-modal-controls">
    <%= f.buttons do %>
      <%= f.commit_button 'Insert Subscription Form' %>
    <% end %>
  </div>
<% end %>

And get the following error:

Rendered mercury/snippets/subscription_options.html.erb (5.8ms)
Completed 500 Internal Server Error in 9ms
ActionView::Template::Error (undefined method 'campaign_id' for {}:Hash):
    4:   <div class="mercury-modal-pane-container">
    5:     <div class="mercury-modal-pane">
    6:       <%= f.inputs 'Options' do %>
    7:         <%= f.input :campaign_id, :required => true, :as => :select, 
    8:                  :collection => { "Google Adwords" => 1, "Facebook Ad" => 2, "No Referrer" => 3 },
    9:                  :input_html => { :value => @options[:campaign_id] || 1, :allow_blank => true } %> 
    10:                     
  app/views/mercury/snippets/subscription_options.html.erb:7:in 'block (2 levels) in _app_views_mercury_snippets_subscription_options_html_erb___2314300290869354519_70344109546800'
  app/views/mercury/snippets/subscription_options.html.erb:6:in 'block in   _app_views_mercury_snippets_subscription_options_html_erb___2314300290869354519_70344109546800'
  app/views/mercury/snippets/subscription_options.html.erb:2:in _app_views_mercury_snippets_subscription_options_html_erb___2314300290869354519_70344109546800'

Ultimately I'd like the collection to come from database but I was trying to take baby steps and it failed here. How do I construct an option parameter that provides a drop down select? I have Formtastic included in the Gemfile and if I use just normal text box inputs it works fine.

jejacks0n commented 12 years ago

Hi Dom, while I'm willing to provide support for Mercury Editor, I'm unable to provide support for everything else that's rails based. I understand that it can be difficult to determine where an error is coming from (server vs. javascript), but this one's rails.. You can assume this any time you see a HTTP 500 response.. You can also determine this from the "500 Internal Server Error" that you see at the top of that response.

It looks like you're building a form using a hash.. formtastic typically expects a model / openstruct that responds to specific methods. Try the baby steps the other way first -- making the models and such.. not using mercury.. then integrating it into mercury might be easier.

jocubeit commented 12 years ago

The code I provided above is only a slight alteration from your own example snippet in the gem:

mercury/app/views/mercury/snippets/example_options.html.erb

The only difference is the select input field. From what I can see this is valid Formtastic syntax. I may be using a hash but I've taken that from your own example, and since that works, I don't see why this doesn't.

I will take your advice and build a database-backed AR model and see if I get it to work that way.

Thanks for your time.