0

クリックすると、コントローラーに追加した次のアクションをトリガーするlink_toまたはbutton_toを作成する方法を見つけようとしています

def send_notification
    @event = Event.find(params[:id])
    @users = User.where(:team_id => current_user[:team_id]).all
    @account_sid = '@@@@'
    @auth_token = '@@@@'# your authtoken here
    @client = Twilio::REST::Client.new(@account_sid, @auth_token)
    @account = @client.account

    if @event.update_attributes(params[:event])
      @users.each do |u|
        #Starts the SMS process
        #Uncomment to enable the SMS process
        team = truncate(u.team.name, :length => 15, :omission => '')
        opponent = truncate(@event.opponent.name, :length => 10, :omission => '')
        date = @event.datetime.strftime("%a, %e %b, %Y")
        time = @event.datetime.to_s(:event_time)
        location = truncate(@event.location.name, :length => 15, :omission => '')
        if u.mobile
          @message = @account.sms.messages.create({
                    :from => '+@@@@',
                    :to => "+#{phone_number(u.mobile, :Australia)}",
                    :body => "#{u.first_name}: #{team} v #{opponent} #{date} #{time}@ #{location}" })
          puts @message
        end
        @availability = u.availabilities.update(:unique_id => Base64.encode64("#{u.id.to_s}_#{@event.id.to_s}_#{@event.team.id.to_s}"))
        Notifier.event_added(u,@event).deliver
      end
    end
  end

そして私は私のルートに以下を追加しました

resources :events do
    post 'send_notifications'
    get 'page/:event_page', :action => :index, :on => :collection
  end

rake ルートの出力 event_send_notifications POST /events/:event_id/send_notifications(.:format)

コードを見る =button_to 'Send Notifications' , event_send_notifications_path, :class => 'button'

エラー No route matches {:action=>"send_notifications", :controller=>"events"}

4

2 に答える 2

1

コントローラー アクションの名前を に変更しますsend_notifications
アクションにはいくつかのパラメーターが必要なので、それらも提供する必要があります。じゃあこんな風に使おう

=button_to('Send Notifications' , send_notifications_event_path(params), :action => 'send_notifications' , :class => 'button')

paramこれがパラメーターのハッシュです。アクションが期待するものです。

また、あなたのアクションをRESTfulにしてください

resources :events do
    post 'send_notifications', :on => :member
    get 'page/:event_page', :action => :index, :on => :collection
end

それが役立つかどうか、または同じエラーが再び発生するかどうかをお知らせください。

于 2013-04-28T07:25:13.497 に答える