ruby on rails - Why is this form redirecting me before giving me a chance to enter data? -
rails controller:
class venuescontroller < applicationcontroller def new @venue = venue.new end def create @venue = venue.new(params[:venue]) if @venue.save redirect_to root_path end end def update redirect_to search_path end end
rails form:
<%= form_for(@venue) |f| %> <%= f.text_field :foursquare_id %> <%= f.submit "save" %> <% end %>
"foursquare_id" column in "venues" table. import foursquare id foursquare i'm typing in text testing purposes. being redirected "root_path" before being given chance type form.
what controller/form missing? thank in advance
the template form should used new
action new.html.erb
filename. , should going /venues/new
fill out form.
the create
action used submit completed form, why getting redirected. should modify create
handle model couldn't save:
def create @venue = venue.new(params[:venue]) if @venue.save redirect_to root_path else render :action => :new end end
or can use shorthand this:
def create @venue = venue.new(params[:venue]) @venue.save respond_with @venue, :location => root_path end