samedi 30 novembre 2019

undefined local variable or method `article_params' for

articles_controller.rb

''' class ArticlesController < ApplicationController def index @articles = Article.all end

def show
  @article = Article.find(params[:id])
end

def new
end

def create
  @article = Article.new(article_params)

  if @article.save
    redirect_to @article
  else
    render new
end

private
  def article_params
    params.require(:article).permit(:title, :text)
  end
end

end

'''

routes.rb

'''

Rails.application.routes.draw do
  #layout=false 
  get 'welcome/index'
  get 'welcome/second'
  get 'articles/new'
  post 'articles/new'
  #get 'articles/show'
  #get 'articles/index'
  #get 'articles/new'
  resources :articles
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
  root 'welcome#index'
end'

'''

show.html.erb

'''

Rails.application.routes.draw do
  #layout=false 
  get 'welcome/index'
  get 'welcome/second'
  get 'articles/new'
  post 'articles/new'
  #get 'articles/show'
  #get 'articles/index'
  #get 'articles/new'
  resources :articles
  # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
  root 'welcome#index'
end

'''

index.html.erb '''

<h1>Listing articles</h1>

<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
    <th></th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
      <td><%= link_to 'Show', article_path(article) %></td>
    </tr>
  <% end %>
</table>

'''

new.html.erb

'''

<%= form_for :article, url: articles_path do |form| %>
 <h1>new artical page</h1>
  <p>
    <%= form.label :title %><br>
    <%= form.text_field :title %>
  </p>

  <p>
    <%= form.label :text %><br>
    <%= form.text_area :text %>
  </p>

  <p>
    <%= form.submit %>
  </p>
<% end %>

'''

schema.rb

'''

ActiveRecord::Schema.define(version: 2019_11_30_073138) do

  create_table "articles", force: :cascade do |t|
    t.string "title"
    t.text "text"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

end

'''

database.yml

'''

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: db/test.sqlite3

production:
  <<: *default
  database: db/production.sqlite3

'''

yymmddttss_create_articles.rb

'''

 class CreateArticles < ActiveRecord::Migration[6.0]
  def change
    create_table :articles do |t|
      t.string :title
      t.text :text

      t.timestamps
    end
  end
end

'''

i don't know where im making mistake. please when you reply it then make changes in above codes.

Aucun commentaire:

Enregistrer un commentaire