2013-07-22 57 views
0

因此,我一直在使用ruby在rails上開發Web應用程序。我在我的主頁上有表單標籤,但是當我點擊提交時,它無法將信息保存到客人或當前用戶(我正在使用設計)並重定向到不同的頁面。該應用程序不給我任何錯誤,它只是不會收到的信息。預先感謝您的幫助!Form_tag提交軌道

class PageController < ApplicationController 
    def home 
    unless @button.nil? 
     @location = Place.create(:address => params[:place], :phone_number => params[:phone], :name => params[:title], :status => "not_purchased", :user_id => current_or_guest_user.id) 
     @location.save! 
     if @location.save && [email protected]? 
     redirect_to places_path 
     end 
    end 
    end 

    def index 
    end 


    def show 
    respond_to do |format| 
     format.html # show.html.erb 
     format.json { render json: @location } 
    end 
    end 

    def new 
    end 


    def create 
    unless @button.nil? 
     @location = Place.create(:address => params[:place], :phone_number => params[:phone], :name => params[:title], :status => "not_purchased", :user_id => current_or_guest_user.id) 
     @location.save! 
     if @location.save 
     format.html { redirect_to places_path} 
     format.json { render action: 'index', status: :created, location: places_path } 
     else 
     format.html { render action: 'new' } 
     format.json { render json: @location.errors, status: :unprocessable_entity } 
     end 
    end 
    end 


    def map 
    end 



end 

頁/ home.html.erb

<section id="content"> 
    <div class="container"> 
    <div class="inside"> 
     <div class="wrapper row-1"> 
     <div class="box col-1 maxheight"> 
      <div class="border-right maxheight"> 
      <div class="border-bot maxheight"> 
       <div class="border-left maxheight"> 
       <div class="left-top-corner maxheight"> 
        <div class="right-top-corner maxheight"> 
        <div class="right-bot-corner maxheight"> 
         <div class="left-bot-corner maxheight"> 
         <div class="inner"> 
          <h3>Check Availability</h3> 
          <section style="border: 1px solid black;padding: 10px; margin:10px"> 
          <h5>Add your site(s)</h5> 
          <b><%= field_set_tag '' do %> </b> 
            <%= form_tag do %> 
             <p> 
             <%= label_tag 'title', "Name of Site"%> 
             <%= text_field_tag 'title', nil, :placeholder => "Enter your site name", :size => 40%><br/> 
             </p> 
             <p> 
             <%= label_tag 'place', "Address"%> 
             <%= text_field_tag 'place', nil, :placeholder => "Enter your address", :size => 40%><br/> 
             </p> 
             <p> 
             <%= label_tag 'phone', "Phone number"%> 
             <%= text_field_tag 'phone', nil, :placeholder => "Enter your phone number", :size => 40%><br/> 
             </p> 
             <p><span><span><%[email protected] = submit_tag "Add me!", data: {:confirm => "Are you sure?"}%></span></span></p> 
            <% end %> 
           <% end %> 
         </div> 
         </div> 
        </div> 
        </div> 
       </div> 
       </div> 
      </div> 
      </div> 
     </div> 
     </div> 
     <div class="clear"></div> 
    </div> 
    </div> 
    </div> 
    </div> 
</section> 

回答

0

你或許可以讓你的表格前擺脫field_set_tag的。不知道這是什麼目的,因爲你沒有傳遞任何東西。

然後在你的form_tag補充一點:

<%= form_tag @location do %> 

哪裏@location是對象的形式是約。你沒有創造它有

@location = Place.create(:address => params[:place], :phone_number => params[:phone], :name => params[:title], :status => "not_purchased", :user_id => current_or_guest_user.id) 
    @location.save! 

而且從你家這個控制器刪除。您正在使用您的create操作創建它。因此,在您#home行動,而不只是實例什麼@location是:

@location = Place.new user_id: current_or_guest_user.id 
0

在您的網頁/ home.html.erb觀點,form_tag需要一個指向控制器動作的URL。它的空白ATM因此默認爲POST操作,但它不會發布任何內容。嘗試:

<%= form_tag @location do %> 

另外,@button實例變量總是等於零,因爲它似乎沒有被初始化到任何地方。