0

我希望我的交付控制器接收与此类似的 URL 参数:

https://www.xxxxx.com/messages/delivery?id=ones1sbn&type=1

我的.delivery动作MessagesController如下所示:

def delivery
  sent_message =  SentMessage.find_by_ref(params[:id])
  if params[:type] == 1
    sent_message.delivery = "Delivered"
    sent_message.save()
  elsif params[:type] == 2
    sent_message.delivery = "Delivery Failure"
    sent_message.save()
  else 
    sent_message.save() 
  end
end

那么路由条目是

resources :messages do
  collection do
    get 'delivery'
  end
end

我无法从传入的 HTTP 请求中接收信息的原因可能是什么?

消息控制器中的过滤器是

before_filter :authenticate_user!, :except => [:delivery, :show]
load_and_authorize_resource :except => [:delivery, :show]

为这个动作耙路线

 delivery_messages GET        /messages/delivery(.:format)                          messages#delivery

在所有更新之后,现在是错误;

Template is missing

Missing template messages/delivery, application/delivery with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :slim, :arb]}. Searched in: * "/var/www/html/webapp/app/views" * "/usr/local/lib/ruby/gems/1.9.1/gems/activeadmin-0.6.0/app/views" * "/usr/local/lib/ruby/gems/1.9.1/gems/kaminari-0.14.1/app/views" * "/usr/local/lib/ruby/gems/1.9.1/gems/devise-3.1.0/app/views"

添加了模板,但仍然没有来自 http 请求的更新

4

1 回答 1

1

使用get代替match,如下所示:

get 'messages/delivery' => 'messages#delivery'

更新

根据您的评论,听起来您的 routes.rb 文件中有一个宁静的资源路径,该路径在到达get交付线之前首先与 URL 匹配。大概是这样的resources :messages

正如我在评论中所说,请记住路由匹配按照它们在该文件中出现的顺序进行检查。您可以将get上面的resouces行放在上面,或者试试这个:

resources :messages do
    collection do
        get :delivery
    end
end

这应该映射messages/delivery:delivery您的MessagesController. 做一个rake routes验证。

于 2013-09-24T01:03:40.137 回答