2017-04-18 16 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 %> 

これは機能しません。私はボタンをクリックすると、それはエラー - Noルートマッチ[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は非推奨になりました。

/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:警告:constant :: Fixnumは推奨されていません

レーキが中止されました!

ArgumentError:ルート定義のコントローラキーがありません。ルートを確認してください。レール/奨学金/奨学金/設定/ routes.rbを上

/ホーム/ gauri /アカデミック/ CS /ルビー:25:ブロック `で「

/ホーム/ gauri /アカデミック/ CS/RubyでRailsの上/ScholarShip/ScholarShip/config/routes.rb:1:in ` 'Railsの/奨学金/奨学金/設定/ environment.rbに上

/ホーム/ gauri /アカデミック/ CS /ルビー:5:`で'

タスク:TOP => routes => environment

+0

リンクするものを眺めたいですか? 'rake routes'を実行し、出力をポストしてください。 –

+0

あなたのルートはすべて「取得」リクエストです。フォームのデータをコントローラーに「ポスト」するルートを追加する必要があります。投稿 'input_output/SignUp' – bkunzi01

+0

@AlejandroMontillaこれは、「サインアップ」ページと「ログイン」ページも含まれるInputOutputというコントローラの一部である「micropost」というビューにリンクしたいと思います。 – 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名前空間の下にそれを入れている場合、それは私がマイケル・ハートによってRailsのチュートリアルの本をお勧めします。この

resources :input_outputs do 
    resources :users 
end 

ようなものになるだろう。このようなことを非常に詳細に行う方法を示しています。それは古典です。

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' 
関連する問題