ruby on rails - Getting a "NoMethodError in Boards#show" error when going to #new action (not trying to access a method, and the variable exists) -
i'm new ruby on rails, forgive if stupid mistake.
i used rails generate scaffold command generate "board" scaffold title:string , message:text. now, i'm trying go localhost:3000/boards/new , i'm getting "nomethoderror in boards#show" error when try access board.message. don't get error when try access board.title.
code:
form.html.erb
<%= form_for(@board) |f| %> <% if @board.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@board.errors.count, "error") %> prohibited board being saved:</h2> <ul> <% @board.errors.full_messages.each |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="field"> <%= f.label :title %><br /> <%= f.text_field :title %> </div> <div class="field"> <%= f.label :message %><br /> <%= f.text_area :message %> </div> <div class="actions"> <%= f.submit %> </div> <% end %> i'm getting error on line 20 (<%= f.text_area :message %>)
board.rb
class board < activerecord::base attr_accessible :message, :title has_many :posts end *boards_controller.rb*
class boardscontroller < applicationcontroller # /boards # /boards.json def index @boards = board.all respond_to |format| format.html # index.html.erb format.json { render json: @boards } end end # /boards/1 # /boards/1.json def show @board = board.find(params[:id]) respond_to |format| format.html # show.html.erb format.json { render json: @board } end end # /boards/new # /boards/new.json def new @board = board.new respond_to |format| format.html # new.html.erb format.json { render json: @board } end end # /boards/1/edit def edit @board = board.find(params[:id]) end # post /boards # post /boards.json def create @board = board.new(params[:board]) respond_to |format| if @board.save format.html { redirect_to @board, notice: 'board created.' } format.json { render json: @board, status: :created, location: @board } else format.html { render action: "new" } format.json { render json: @board.errors, status: :unprocessable_entity } end end end # put /boards/1 # put /boards/1.json def update @board = board.find(params[:id]) respond_to |format| if @board.update_attributes(params[:board]) format.html { redirect_to @board, notice: 'board updated.' } format.json { head :no_content } else format.html { render action: "edit" } format.json { render json: @board.errors, status: :unprocessable_entity } end end end # delete /boards/1 # delete /boards/1.json def destroy @board = board.find(params[:id]) @board.destroy respond_to |format| format.html { redirect_to boards_url } format.json { head :no_content } end end end routes.rb
anonymous::application.routes.draw resources :boards resources :posts root :to => "boards#index" end can please explain me?
Comments
Post a Comment