Мне не удается получить доступ к действию show с моего вложенного контроллера. Я могу создать объект, но redirect_to
не удается.
routes.rb
blog_topic_posts POST /blog/topics/:topic_id/posts(.:format) blog/posts#create
edit_blog_topic_post GET /blog/topics/:topic_id/posts/:id/edit(.:format) blog/posts#edit
blog_topic_post GET /blog/topics/:topic_id/posts/:id(.:format) blog/posts#show
PUT /blog/topics/:topic_id/posts/:id(.:format) blog/posts#update
DELETE /blog/topics/:topic_id/posts/:id(.:format) blog/posts#destroy
new и create actions:
def new
@post = Post.new
@tag = @post.tags.build
end
def create
@post = Post.new(params[:post])
@post.user = current_user
respond_to do |format|
if @post.save
flash[:success] = 'Post was successfully created.'
format.html { redirect_to([:blog, @topic, @post]) }
else
format.html { render action: :new }
end
end
end
Когда я передаю вышеупомянутый редирект, он возвращает ошибку маршрутизации:
NoMethodError in Blog::PostsController#create
undefined method `blog_post_url' for #<Blog::PostsController:0x00000002ee34f8>
{"utf8"=>"✓",
"authenticity_token"=>"dN9feAsRVJal9P1YDtgEeHHwsP4yr3rZT1KBjgR57SI=",
"post"=>{"title"=>"ban",
"description"=>"bobobo",
"content"=>"---- sequi- molestias- qui- veritatis- quasi- modi- praesentium- nesciunt- voluptates- exercitationem",
"topic_id"=>"1",
"tags_attributes"=>{"0"=>{"tag_name"=>"bank"}}},
"commit"=>"Create Post"}
Может кто-нибудь объяснить, почему этот маршрут терпит неудачу? И почему он не ищет blog_topic_post_url? кроме того, следующее перенаправление в том же контроллере работает для PUT ...
def update
# loading in post object via before_filter
if @post.update_attributes(params[:post])
flash[:success] = "Post was successfully updated."
redirect_to blog_topic_post_url([@post.topic])
else
flash[:error] = "Post could not be saved."
render :edit
end
end