2

私が投稿しているとき、それは私を連れて行きます

example.com/shop.:community_name

それ以外の

example.com/shop/:community_name

私のroutes.rb

resources :communities, :path => "shop", do
    resources :community_topics, :path => "topic", :as => :'topic'
end

_form.html.erb

<%= form_for @community, :html => { :class => 'form-horizontal' } do |f| %>
...
    <%= f.submit nil, :class => 'btn btn-primary' %>
    <%= f.submit 'Destroy', 
    :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
    :class => 'btn btn-danger', :name => 'destroy' unless @community.new_record? %>
<% end %>

communitys_controller.rbのアクションを更新しますto_paramを使用するので、community_nameを使用します

def update

        @community = Community.find_by_community_name(params[:id])      

        respond_to do |format|
            if @community.update_attributes(params[:community])
                format.html { redirect_to communities_path(@community.community_name), notice: 'Community was successfully updated.' }
                format.json { head :no_content }
            else
                format.html { render action: "edit" }
                format.json { render json: @community.errors, status: :unprocessable_entity }
            end
        end
end
4

2 に答える 2

1

そのはず

... redirect_to community_path(@community.community_name) ...

あなたのupdate行動でCommunitiesController

于 2012-12-24T01:30:36.887 に答える
1

名前付きルートが嫌い...

redirect_to @community
于 2012-12-24T01:35:12.400 に答える