2013-04-28 2 views
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 => '[email protected]@@@', 
        :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 

выход рек маршрутов 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"}

ответ

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 

Позвольте мне знать, если это помогает или если вы получаете ту же ошибку снова.

+0

теперь получает 'Нет совпадений маршрутов {: action =>" show ",: controller =>" events ",: id =>" 27 "}' –

+0

Проверьте маршрут маршрута в 'рейх-маршрутах'. Кроме того, попробуйте 'post 'send_notifications',: on =>: member' один раз. – kiddorails

+0

путь от маршрутов 'event_send_notifications POST /events/:event_id/send_notifications(.:format) events # send_notifications' –

0

Вы назвали ваше действие контроллера send_notification (в единственном числе), но в маршрутах используется множественное число send_notifications. Вы должны выбрать один или другой и называть их одинаковыми.

+0

обновили, по-прежнему получают ту же ошибку –

+0

перезапустили ли вы свой сервер? –

+0

перезапустил сервер, по-прежнему отображает ту же ошибку –

Смежные вопросы