Coder Social home page Coder Social logo

ruby's Introduction

ruby

Some ruby snippets

ruby's People

Contributors

mshahriarinia avatar

Watchers

James Cloos avatar  avatar

ruby's Issues

ActiveModel::ForbiddenAttributesError in PostsController#update

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"}

Render "new" Not Working

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

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.

views/layouts/application.html.erb Flash Message Handling

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 %>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.