点击提交按钮不起作用

时间:2014-04-11 16:08:45

标签: ruby-on-rails ruby-on-rails-4

当我点击提交按钮时,表单未提交。还有一个领域可以提交评级(:点)。你点击一个星号,它应该是hidden_​​field的值。

<%= form_for [@post, @comment], remote: true, method: :post, 'data-update-target' => 'comments', class: 'comments' do  |f| %>

...

    <%= f.hidden_field :point %>
  <div class="rating-comments"></div>

    <script type="text/javascript">
        $('.rating-comments').raty({
          click: function(score, evt) {
            $("#point").val(score);
            return console.log(score);
          }
        });
    </script>

...

  <div class="actions">
    <%= f.submit " Submit ", :class => "btn btn-primary" %>
  </div>

<% end %>
...

comments.coffee文件

ready = ->
  $("form[data-update-target]").bind "ajax:success", (evt, data) ->
    target = $(this).data("update-target")
    $("#" + target).prepend data
    $('#content').val('')

  score = $('.rating-total').data('score')
  $('.rating-total').raty({
    haftShow: true,
    score: score,
    readOnly: true
  })

$(document).ready(ready)
$(document).on('page:load', ready)

LOG

Started POST "/posts/1/comments" for 92.241.136.221 at 2014-04-11 16:25:46 +0000                                                                                                  
Processing by CommentsController#create as JS                                                                                                                                      
  Parameters: {"utf8"=>"✓", "comment"=>{"point"=>"-1", "title"=>"", "content"=>""}, "score"=>"4", "commit"=>" Submit ", "post_id"=>"1"}                                           
  Post Load (0.3ms)  SELECT "[posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1  [["id", "1"]]                                                                                      
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1  [["id", 1]]                                                                                        
   (0.1ms)  begin transaction                                                                                                                                                         
   (0.1ms)  rollback transaction                                                                                                                                                      
  Rendered shared/_categories.html.erb (0.9ms)                                                                                                                                        
  Rendered comments/_form.html.erb (5.5ms)                                                                                                                                                                                                                                                                           
   (0.2ms)  SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."followed_id" WHERE "relationships"."follower_id" = ?  [["follower_id", 1]]     
   (0.3ms)  SELECT COUNT(*) FROM "users" INNER JOIN "relationships" ON "users"."id" = "relationships"."follower_id" WHERE "relationships"."followed_id" = ?  [["followed_id", 1]]     
  Rendered shared/_stats.html.erb (123.0ms)                                                                                                                                           
  Rendered shared/_user_mainprofile.html.erb (125.2ms)                                                                                                                                
  Rendered comments/new.html.erb within layouts/application (135.6ms)                                                                                                             
  Rendered layouts/_header.html.erb (0.6ms)                                                                                                                                           
Completed 200 OK in 230ms (Views: 214.9ms | ActiveRecord: 1.1ms | Solr: 0.0ms)

0 个答案:

没有答案