【问题标题】:Rails View not rendered through javascriptRails View 未通过 javascript 呈现
【发布时间】:2015-07-17 16:32:49
【问题描述】:

我有一个 show.html 文件,它有<a ng-click="writeReview(product)" class="vote-link">Review</a>

我的 javascript 文件包含

$scope.writeReview =(product) ->  
  $http.get("/products/#{product.id}/review/new")

在我的 ReviewController 中调用新方法。

对应的路由是get '/products/:product_id/review/new', to: "reviews#new", defaults: { format: 'html' }

但问题是在单击 show.html 中的 Review 按钮时视图未呈现在 views/reviews/new.html.erb 中。

但是当我从 URL 栏中点击路由 products/2/review/new 时,视图被呈现。甚至这两个调用的日志,即来自 html 文件的 Review 按钮以及来自直接 URL 栏的点击都是相同的。

【问题讨论】:

    标签: javascript html ruby-on-rails angularjs coffeescript


    【解决方案1】:

    你可以通过在你的 js 中添加这行来做到这一点:

    $scope.writeReview =(product) -> 
     $location.path '/products/' + product.id + '/review/new'
     $location.replace()
    

    【讨论】:

    • 谢谢..但是 window.location.href = "/products/#{product.id}/review/new" 成功了!
    猜你喜欢
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 2014-05-01
    • 1970-01-01
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 2020-04-10
    相关资源
    最近更新 更多