Some ruby snippets
mshahriarinia / ruby Goto Github PK
View Code? Open in Web Editor NEWSome ruby snippets
Some ruby snippets
ActiveModel::ForbiddenAttributesError in PostsController#update
ActiveModel::ForbiddenAttributesError
Extracted source (around line #73):
@post = Post.find(params[:id])
if @post.update_attributes(params[:post])
redirect_to posts_path, :notice => "Your post has been updaetd"
else
render "edit"
Rails.root: /Users/morteza/Dropbox/workspaces/ruby/ruby_on_rails/blog
Application Trace | Framework Trace | Full Trace
app/controllers/posts_controller.rb:73:in `update'
Request
Parameters:
{"utf8"=>"โ",
"_method"=>"patch",
"authenticity_token"=>"VlpNO1flekb9xqkVH7d6TcomhuQLISPts2iI9EMHtPI=",
"post"=>{"title"=>"@post = Post.find(params[:id])",
"content"=>"d"},
"commit"=>"Update Post",
"id"=>"4"}
When we fail at creating a new post we need to reshow the new page, but it takes us to posts_path instead.
./app/controllers/posts_controller.erb
def create # form from the new action will submit to and this will save the post into the datasbe
@post = Post.create( params.require(:post).permit(:title, :content))
if @post
redirect_to posts_path, :notice => "Your post was saved."
else
render "new"
end
end
Mass assignment is taken care of by attr_accssible in model for rails 3.0 but for rails 4.0 we need to use strong_parameters in controller. Will catch upon that later on as it's a bit obscure for now.
This code does not handle flash messages. An alternative is required.
<%= flash.each do |key, value| %> <!--We have access to this flash hash amd loop through it and pass it a block access its key and values-->
<p><%= value %></p> <!--key is hte type of message, value is The actual message itself.-->
<!---->
<% end %>
It does not show the validation messages on modifying Post model.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.