交換したい:
<%= button_tag "Create" , :class => "round" %>
為に
<%= link_to trips_path(@trip), :class => "round", :method => :post do %>
<div id="createtrip_button_newtrip">
Create
</div>
<% end %>
フォームで
<%= form_for @trip, :html =>{ :multipart => true} do |f| %>
<div class="field">
<%= f.label :name %><br/>
<%= f.text_field :name %>
</div>
<div id="description_container_newtrip">
<%= f.label :description %><br/>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :location %><br/>
<%= f.text_field :location %>
</div>
<div class="field">
<%= f.label :start_date, "Start Date:" %><br/>
<%= f.date_select :start_date, :order => [:month, :day, :year] %>
</div>
<div class="field">
<%= f.label :end_date, "End Date:" %><br/>
<%= f.date_select :end_date, :order => [:month, :day, :year] %>
</div>
<div class="field">
<%= f.hidden_field :user_id %>
</div>
<div class="field">
<%= f.hidden_field :traveldeal_id %>
</div>
<%= #button_tag "Create", :class => "round" %>
<%= link_to trips_path(@trip), :class => "round", :method => :post do %>
<div id="createtrip_button_newtrip">
Create
</div>
<% end %>
<% end %>
link_to は正しいコントローラーで正しいアクションを呼び出しますが、フォームが保存されません。メソッドは次のとおりです。
def create
@trip = Trip.new(params[:trip])
if @trip.save
redirect_to root_path
else
redirect_to login_path
end
end
login_path にリダイレクトされ続けます。私の問題は、 @trip のパラメーターをコントローラーに送信していないことだと思います。
任意のヒント?
編集:
私の開発ログからの params ハッシュは次のとおりです。
Started POST "/trips" for 127.0.0.1 at 2012-04-07 15:23:37 -0700 Processing by TripsController#create as HTML Parameters: {"authenticity_token"=>"+D2icFw2pz6qwYVaeXoWg5MOJg+Sks5/ckN0lVn1r4o="} [1m[36m (0.1ms)[0m [1mbegin transaction[0m [1m[35m (0.0ms)[0m rollback transaction Redirected to http://localhost:3000/login Completed 302 Found in 2ms (ActiveRecord: 0.1ms)