2

I have a plain old form. That form is used to create new objects of a nested model.

#restaurant.rb
has_many :courses
#courses.rb
belongs_to :restaurant
#routes.rb
resources :restaurants do
  resources :courses
end

In my views(in haml), i have that code:

%li.course{'data-random'=>random}
  = form_for([restaurant,course], :remote=>true) do |f|
    .name= f.text_field :name, :placeholder=>'Name here'
    .cat= f.hidden_field :category
    .price= f.text_field :price,:placeholder=>'Price here'
    .save
      = hidden_field_tag :random,random
      = f.submit "Save"

I espected that form to be answered by action create of courses_controller with JS (create.js.erb), but it is submited like a normal form, and is answered with html.

What am I doing wrong? This problem is similar to this but the only answer don't make sense to me. Thanks

Inside

Community
  • 1
  • 1
miguel.camba
  • 1,777
  • 1
  • 14
  • 19

1 Answers1

1

Do you have in your controller respond with js format format.js { render :layout => false } and your create view should be create.js.rjs(i am talking about rails 3)

codevoice
  • 474
  • 3
  • 6