2017-04-18 22 views
1

我有一個登錄頁面和一個註冊頁面。我想要點擊登錄或註冊按鈕後,用戶被重定向到另一個視圖,這將是一個微博。重定向按鈕在Ruby on Rails中查看

註冊頁面的代碼如下。 (如在表格部分) -

<h2 class="text-center">Sign Up</h2> 
       <%= form_for(input_output_SignUp_url) do |f| %> 
       <%= f.label :first_name,"First name:" %> 
       <%= f.text_field :first_name %> 

       <%= f.label :last_name,"Last name:" %> 
       <%=f.text_field :last_name %> 

       <%= f.label :email,"Email:" %> 
       <%= f.email_field :email %> 

       <%= f.label :phone,"Phone no:"%> 
       <%= f.text_field :phone %> 

       <%= f.label :city,"City:" %> 
       <%= f.text_field :city %> 

       <%= f.label :addr_1,"Address 1:" %> 
       <%=f.text_field :addr_1 %> 

       <%= f.label :addr_2,"Address 2:" %> 
       <%= f.text_field :addr_2 %> 

       <%= f.label :state,"State:"%> 
       <%= f.text_field :state %> 

       <%= f.label :postal_code,"Postal Code:"%> 
       <%= f.text_field :postal_code %> 

       <%= f.label :password,"Password:"%> 
       <%= f.password_field :password %> 

       <%= f.label :password_confirmation, "Confirmation:" %> 
       <%= f.password_field :password_confirmation, class: 'form-control' %> 

       <%= button_to "View profile", input_output_micropost_path%> 
      <% end %> 

現在這是行不通的。當我按一下按鈕,它顯示了一個錯誤 - 沒有路由匹配[POST]「/ input_output /註冊」

的路由文件如下: -

root 'static_pages#home' 

    get 'static_pages/home' 
    get 'static_pages/genre' 
    get 'static_pages/accessories' 
    get 'static_pages/contactus' 
    get 'static_pages/aboutus' 

    get 'input_output/Login' 
    get 'input_output/SignUp' 
    get 'input_output/micropost' 

    get '/genre', to: 'static_pages#genre' 
    get '/accessories', to: 'static_pages#accessories' 
    get '/aboutus', to: 'static_pages#aboutus' 
    get 'contactus', to: 'static_pages#contactus' 

    get 'Home', to: 'static_pages#home' 
    get '/Login', to: 'input_output#Login' 
    get '/micropost', to: 'input_output#micropost' 
    get '/SignUp', to: 'input_output#SignUp' 
end 

我怎樣才能讓這個錯誤消失了?

編輯: - 作爲問,這是耙路線 /home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/activesupport-5.0的結果。 1/lib/active_support/xml_mini.rb:51:警告:常量:: Fixnum已棄用

/home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/ activesupport-5.0.1/lib/active_support/xml_mini.rb:52:warning:constant :: Bignum is deprecated

/home/gauri/.rbenv/versions/2.4.0/lib/ruby/gems/2.4。 0/gems/activesupport-5.0.1/lib/active_support/core_ext/numeric/conversions.rb:138:warning:constant :: Fixnum已棄用

耙子中止了!

ArgumentError:缺失:路由定義中的控制器鍵,請檢查您的路由。

/家庭/薇思瓦納/教學/ CS/Ruby on Rails的/獎學金/獎學金/配置/ routes.rb中:25:在'塊'

/家庭/薇思瓦納/教學/ CS/Ruby on Rails的/ScholarShip/ScholarShip/config/routes.rb:1:in` '

/家庭/薇思瓦納/教學/ CS/Ruby on Rails的/獎學金/獎學金/到config/environment.rb:5:`'

任務:TOP => routes =>環境

+0

做你想要什麼關聯看法?請運行'rake routes'併發布輸出。 –

+0

您的所有路線都是「獲取」請求。你需要添加一條路徑,將數據從表單「張貼」到一個控制器,以及你正在處理的行爲。發佈'input_output/SignUp' – bkunzi01

+0

@AlejandroMontilla我想將它鏈接到名爲'micropost'的視圖,它是控制器的一部分,名爲InputOutput,它也包含註冊頁面和登錄頁面。 – sindhugauri

回答

0

這很簡單。取而代之的

<%= button_to "View profile", input_output_micropost_path%> 

使之成爲提交

<%= f.submit "Sign up", class: "btn btn-default" %> 

然後在您的創建動作控制器在末尾添加一個重定向。像這樣的東西

def create 
    @user = User.new(user_params) 
    if @user.save 
    redirect_to input_output_micropost_path, notice: 'User was successfully created.' 
    else 
    render :new 
    end 
end 

編輯: 您的用戶模型需要RESTful路由。如果你把該input_output命名空間下它會是這樣的

resources :input_outputs do 
    resources :users 
end 

我建議Rails的教程書邁克爾·哈特。它展示瞭如何以非常詳細的方式做這樣的事情。這是一個經典。

0

你的路由的頂部是錯了,路由必須指向控制器內部控制器和動作,所以路線應該是這樣的:

 
    root to: 'static_pages#home' 
    get '/genre', to: 'static_pages#genre' 
    get '/accessories', to: 'static_pages#accessories' 
    get '/aboutus', to: 'static_pages#aboutus' 
    get '/contactus', to: 'static_pages#contactus' 

    get '/Home', to: 'static_pages#home' 
    get '/Login', to: 'input_output#Login' 
    get '/micropost', to: 'input_output#micropost' 
    get '/SignUp', to: 'input_output#SignUp' 
    get '/Home', to: 'static_pages#home' 
    get '/Login', to: 'input_output#Login' 
    get '/micropost', to: 'input_output#micropost' 
    ################################################## 
    #### Action for the form is set as post, so signup 
    #### must be a post route 
    ################################################## 
    post '/SignUp', to: 'input_output#SignUp' 
相關問題