Created
June 1, 2014 22:23
-
-
Save evan-007/5dedf6c2028e0cf02bca to your computer and use it in GitHub Desktop.
angular rails form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Angular form post | |
Started PUT "/api/v1/articles/3" for 127.0.0.1 at 2014-06-02 07:18:52 +0900 | |
Processing by Api::V1::ArticlesController#update as HTML | |
Parameters: {"title"=>"puy98y89y", "body"=>"asdfasdfsdfds\nkjlj", "id"=>"3", "categories"=>[{"name"=>"OOP", "id"=>6}], "category_ids"=>[2, 3, 4], "article"=>{"id"=>"3", "title"=>"puy98y89y", "body"=>"asdfasdfsdfds\nkjlj"}} | |
form: | |
<form name="newArticleForm" ng-submit="newArticleForm.$valid && postArticle(activeArticle)" novalidate> | |
<label>Article Title</label> | |
<input type="text" ng-model="activeArticle.title" name="articleTitle" class="form-control" required> | |
<label>Body</label> | |
<textarea name="articleBody" rows='12' ng-model="activeArticle.body" class="form-control" required></textarea> | |
<label>Categories</label> | |
<select multiple="true" ng-model="activeArticle.category_ids" style="width:200px;" | |
ng-options="category.id as category.name for category in categories"> | |
</select><br/> | |
<input type="submit" class="btn btn-primary" value="Post it!"> | |
</form> | |
Rails controller strong params: | |
private | |
def article_params | |
params.require(:article).permit(:title, :body, :id, | |
category_ids: []) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment