ruby on rails - Setting hidden field value from path parametrs -
i'm stacked. i'm creating application user can create blog, can put posts. associatins are:
blog :has many posts , posts :belongs blog. blog associated user same way. (blogs nested users). show page of post has link:
= link_to 'edit', edit_post_path(blog_id: blog.id)
where send blog_id in hidden form in post. works fine(http address:)
http://localhost:3000/posts/1/edit?blog_id=1
but when press show button of post(after creating) rails trying find blog post id. adress:
and error: couldn't find blog 'id'=2 in line:
= link_to 'edit', edit_post_path(blog_id: blog.id)
the problem if delete parameters of path can not set in hidden form(blog_id) in edit. how should solve it?
upd: routes:
rails.application.routes.draw root to: "pages#index" "users/profile" => "user_blogs#index", :as => "user_root" devise_for :users, controllers: { registrations: "users/registrations" } resources :users resources :blogs end resources :posts resources :comments end end
post controller:
class postscontroller < applicationcontroller respond_to :html before_action :authenticate_user! expose :blog expose :post def show end def new end def edit end def create post.user = current_user post.save respond_with post, location: user_blog_path(post.blog.user, post.blog) end def update post.update(post_params) respond_with post, location: user_blog_path(post.blog.user, post.blog) end def destroy post.destroy respond_with post, location: user_blog_path(post.blog.user, post.blog) end private def post_params params.require(:post).permit(:title, :content, :user_id, :blog_id) end end
Comments
Post a Comment