我想由用户使用多个创建步骤来创建一个事件。目前我有以下问题,它在完成第二步后重定向到第一步。
以下是我的控制器
def new
@event = Event.new(params[:event])
@user = current_user
respond_to do |format|
if @event.save
format.html { render :template => "events/new2" }
format.json { render json: event_new2, status: :created, location: @event }
else
format.html { render action: "new" }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
def event_new2
@event = Event.find(params[:id])
respond_to do |format|
if @event.update_attributes(params[:event])
format.html { render :template => "events/new3" }
# format.json { render json: event_new2, status: :created, location: @event }
else
format.html { render action: "event_new2" }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
# POST /events
# POST /events.json
def create
@event = Event.new(params[:event])
@user = current_user
respond_to do |format|
if @event.save
format.html { redirect_to @event, notice: 'event erfolgreich erstellt.' }
format.json { render json: @event, status: :created, location: @event }
else
format.html { render action: "new" }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
我的模型只需要存在标题和描述。意见如下:
步骤1
<%= simple_form_for (@event), :method => 'new' do |f| %>
<%= f.error_notification %>
<%= f.input :title,:label => 'Event Titel' ,:placeholder=>"Titel des Events"%>
<%= f.text_area :description,:label => 'Beschreibung',:placeholder=>"Beschreibung"%>
<%= f.submit "Event erstellen", class: "btn btn-large btn-primary pull-right"%>
第2步
<%= simple_form_for (@event), :method => 'new' do |f| %>
<%= f.error_notification %>
<%= f.input :category%>
<%= f.input :website, :label=>"Website"%>
有什么帮助吗?提前致谢。