我是 Rails3 的新手,我正在构建非常简单的应用程序(我不想要 AJAX)。无论如何,我有index
和create
行动。该index
动作包含以下形式:
<%= form_for @message, url: promote_index_path do |f| %>
...
<% end %>
我的promote_controller
样子是这样的:
def index
@message = Message.new url: @last_video, message_body: @last_message
end
def create
@message = current_user.messages.new(params[:message])
@message.get_video_id
if @message.save
redirect_to promote_index_url, flash: {notice: "Promotion has been started"}
else
render 'index'
end
end
这一切都很好,除了表单提交成功,并且通知闪烁,如果用户点击F5
,表单会重新提交。这不应该是这种情况,因为我是redirect_to
在成功保存后做的。我相信我在这里做的事情根本上是错误的,所以请帮帮我。
编辑:这是我的routes.rb
resources :home
resources :find
resources :promote
resources :settings
root to: 'home#index'
match 'auth/:provider/callback', to: 'sessions#create'
match 'auth/failure', to: redirect('/')
match 'logout', to: 'sessions#destroy', as: 'logout'
match 'find', to: 'find#index', as: 'find'
match 'promote', to: 'promote#index', as: 'promote'
match 'settings', to: 'settings#index', as: 'settings'
这是我的rake routes
Jans-MacBook-Pro-2:tp3 jan$ rake routes
settings_index GET /settings/index(.:format) settings#index
home_index GET /home(.:format) home#index
POST /home(.:format) home#create
new_home GET /home/new(.:format) home#new
edit_home GET /home/:id/edit(.:format) home#edit
home GET /home/:id(.:format) home#show
PUT /home/:id(.:format) home#update
DELETE /home/:id(.:format) home#destroy
find_index GET /find(.:format) find#index
POST /find(.:format) find#create
new_find GET /find/new(.:format) find#new
edit_find GET /find/:id/edit(.:format) find#edit
find GET /find/:id(.:format) find#show
PUT /find/:id(.:format) find#update
DELETE /find/:id(.:format) find#destroy
promote_index GET /promote(.:format) promote#index
POST /promote(.:format) promote#create
new_promote GET /promote/new(.:format) promote#new
edit_promote GET /promote/:id/edit(.:format) promote#edit
promote GET /promote/:id(.:format) promote#show
PUT /promote/:id(.:format) promote#update
DELETE /promote/:id(.:format) promote#destroy
settings GET /settings(.:format) settings#index
POST /settings(.:format) settings#create
new_setting GET /settings/new(.:format) settings#new
edit_setting GET /settings/:id/edit(.:format) settings#edit
setting GET /settings/:id(.:format) settings#show
PUT /settings/:id(.:format) settings#update
DELETE /settings/:id(.:format) settings#destroy
root / home#index
/auth/:provider/callback(.:format) sessions#create
auth_failure /auth/failure(.:format) :controller#:action
logout /logout(.:format) sessions#destroy
find /find(.:format) find#index
promote /promote(.:format) promote#index
settings /settings(.:format) settings#index
编辑:问题似乎出在谷歌浏览器中。