没有路线匹配[PUT]“/ articles”但我在路线中包含了放置路线

时间:2016-11-20 05:11:23

标签: ruby-on-rails routes aasm

您好我是rails和MVC的新手,但我正在努力学习。现在我正在使用AASM从in_draft转换为已发布。 我能够在rails控制台中进行更改,但在尝试使用link_to时,我在问题中得到了错误

`#/app/views/welcome/dashboard.html.erb
<% if article.may_publish? %>
<%= link_to 'Publish', '/articles/#{article.id}/publish', method: :put, class: "alert-link" %>
<%end%>

这是mi路线

put '/articles/:id/publish', to: 'articles#publish'

我的articles_controller发布方法

def publish
    @article.publish!
    redirect_to @article
end

2 个答案:

答案 0 :(得分:1)

你真的很亲密!您需要使用双引号才能使用#{}进行推断。

def popcount3num(indices):
    '''
    given, in (strictly) ascending order, the indices of bits set
     in the binary representation of a natural number num,
     return the number of bits set in 3*num
    '''
    prev = -3           # position of last bit handled
    count = carry = 0   # carry is for bitposition handled + 2
    for i in indices:
    #   print(i, count, carry)
        if prev == i-1:     # in a run of set bits
            if not carry:
                carry = 1   # "move bit from count to carry"
                count -= 1
            else:
                count += 1  # tally
        else:               # gap
            if not carry:
            # without a carry in, every run produces
            #  two bits at least, including carry out
                count += 2
            elif prev < i-2:
            # if the carry was for a lower position, just tally
                count += 3
                carry = 0
            else:
            # with a carry in, a lone one will change nothing
            # a run will add just as many as without carry
                pass
        prev = i
    return count + carry

应该是:

<%= link_to 'Publish', '/articles/#{article.id}/publish', method: :put, class: "alert-link" %>

答案 1 :(得分:0)

欢迎使用rails。我们建议您使用label添加member操作。 Rails routing

RESTful put

要解决您当前的路线问题,请resources :articles do put :publish, on: :member end

as: :public_article

享受