Reputation: 65
i'm having problems with my page I created .the message i get is above.this is my articles controller.rb page code.learning ruby and the challenges it brings.i'm stuck in this section. And i've been having issues with section.once i post up my code.i don't know if i messed up my codes or something like that.
class ArticlesController < ApplicationController
def index
@articles = Article.all
end
def new
@article =Article.new
end
def edit
@article = Article.new(article_params[:id])
end
def create
@article =Article.new(article_params)
[email protected]
flash[:notice] = "Article was successfully created"
redirect_to article_path(@article)
else
render 'new'
end
end
def update
@article =Article.find(params[:id])
[email protected]
flash[:notice] = "Article was successfully updated"
redirect_to article_path(@article)
else
render 'edit'
end
end
def show
@article =Article.find(params[:id])
end
end
and this is the error page undefined local variable or method `article_params' for #
Extracted source (around line #12): 10 11 12 13 14 15
def edit @article = Article.new(article_params[:id]) end
i get on ruby rails
Upvotes: 0
Views: 1377
Reputation: 979
You forgot to pass article_params to update.
def update
@article = Article.find(params[:id])
if @article.update(article_params)
flash[:notice] = 'Article was successfully updated'
redirect_to article_path(@article)
else
redirect 'edit'
end
end
Upvotes: 0
Reputation: 2076
Yip, as Alfie said above, you're missing your article_params. In rails 4 (which I assume is what you're using) there is the concept of strong paramaters, which is a way of only allowing the fields you're expecting through.
Depending on what fields are in your "article" object, you need to add something like this:
def article_params
params.require(:article).permit(:title, :body)
end
Note, you'll need to adjust it to suit whatever your actual fields are.
Also, might be a copy & paste error, but it's a good idea to get into the habit of indenting your code correctly! Good luck with getting the codes to work :)
Upvotes: 1