ruby - No route matches {:controller=>"stocks", :action=>"create"} RSpec Rails 3 -
I do not understand why I get this error message when I run RSPC:
Failure / Error: Post: Action Controller :: Create a routing error: no root matches {: controller = & gt; "Stock",: Action => "Build"}
Controller stock is present, action type is present, and the path that should be used is:
match / stock / : User_id '= & gt; 'Make stock #' ,:: Through & gt; : Post, as: = & gt; : Query
Root file:
Freeshunter :: App.Rounds.Remove Draw: to = & gt; 'Stock # index' # user_id match 'stock / user_id' = & gt; Add 'Make Stock #' ,:: Through & gt; : Post, as: = & gt; : Query match 'stock /: user_id' = & gt; 'Stock #desk',: = through & gt; : Delete, as: = & gt; : Reset match 'stock /: user_id / update' = & gt; "Stock # update_index" ,: by = & gt; : Post
Stock Controller: (Yes, it will be dry)
Class Stock Controller & lt; ApplicationController def index @user = User.create @user_id_num = @ user.id @ user.stocks = Stock.all @ user.save selected_user_stocks = (UserStock.where ( "user_id = # {@ user_id_num} selected = true")) .take (25) @stocks = UserStock.convert_to_stocks (selected_user_stocks) @pages = Pagination.determine_num_pages (@ user.stocks) end def update_index @user_id_num = params [: user_id] @user = User.find (@user_id_num) selected_user_stocks = UserStock .where ( "user_id = # {@ user_id_num} selected = true") @stocks = UserStock.convert_to_stocks (selected_user_stocks) @pages = Pagination.determine_num_pages (@stocks) @stocks = Stock.display (@stocks, parameter [: PAGENUMBER ] .to_i) Partial render: 'stock_data' end-DEF thinking such shares are auspicious to "create" a new batch of @user_id_num = params [ Land make UserStock.eliminate_stocks (parameters) #: user_id] @user = User.find (@user_id_num) selected_user_stocks = UserStock.where ( "user_id = # {@ user_id_n} Um} selected = true") @stocks = UserStock.convert_to_stocks (selected_user_stocks) @pages = Pagination.determine_num_pages (@stocks) @stocks = Stock.display (@stocks, 1) render partial: 'stock_data' end def destroy stocks_to_reset = UserStock.where ( "user_id = # {params [: user_id ]} ") Stocks_to_reset.each do | User_stock | user_stock.selected = true user_stock.save end @user_id_num = params [: user_id] @user = User.find (@user_id_num) selected_user_stocks = UserStock.where ( "user_id = # {@ user_id_num} and = true selected") @stocks = UserStock.convert_to_stocks (selected_user_stocks) @pages = Pagination.determine_num_pages (@stocks) @stocks = Stock.display (@stocks, 1) render partial: 'stock_data' end end
stock controller Tip: (The trial below has failed)
is required 'spec_helper' RSpec.configure do | Config | Config.infer_spec_type_from_file_location! Finally StocksController reference to "index already" are @user_count = User.all.count @stock_count = Stock.all.count get Description: Index expect it finished (User.all.count) .To "new user making should "eq (@user_count +1) in the end it should all stock associate with the" user "Why do not expect it (User.last.stocks.count) .To eq (@stock_count) finally, reference # Will check "make" is working ... this user posts = User.create May include "stock_list must submit partial": response.should render_template make (partial: "stock_list") end end end
Thanks !!
match 'stock /: user_id' = & gt; 'Make stock #' ,:: Through & gt; : Post, as: = & gt; : Query
tells us that it requires: user_id is a valid path.
post: create
is not: user_id ... so this does not refer to a valid path I can not do it
will change in post: create, user_id = & gt; User.id
Comments
Post a Comment