私が投稿しているとき、それは私を連れて行きます
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