ruby - Weird Rails 4 RESTful URL after form error -
i have restful controller inside of namespace called dashboard, url looks this:
- /dashboard/member
- /dashboard/member/edit
something weird happening when submit member form validation error... shows error it's suppose to, when goes patch url "/dashboard/member" comes ".2" in end:
- /dashboard/member.2
the "2" id of record.
the funny thing did correctly , works great, ".2" thing bothering head.
my controller
class dashboard::memberscontroller < applicationcontroller load_and_authorize_resource :class => member before_filter :authenticate_member! def show end def edit @member ||= current_member end def update @member ||= current_member if @member.update_attributes(member_params) flash[:success] = "profile updated" redirect_to dashboard_member_path else render "edit" end end private def member_params params.require(:member).permit(:first_name, :last_name, :address, :city, :state, :country, :zipcode, :home_phone, :cell_phone) end end
my route
namespace :dashboard resource :member, only: [:show, :edit, :update] end
if meant use resource :member
(instead of resources :member
) should know looks without referencing id
.
here how routes created without id's:
edit_dashboard_member /dashboard/member/edit(.:format) dashboard/members#edit dashboard_member /dashboard/member(.:format) dashboard/members#show patch /dashboard/member(.:format) dashboard/members#update put /dashboard/member(.:format) dashboard/members#update
when sending patch request make sure don't pass argument
it. if pass argument interpreted format(like .html, .js etc)
. in case passed argument 2
or member id 2
for eg:
patch request dashboard_member_path(2)
the route matched against patch /dashboard/member(.:format) dashboard/members#update
2 interpreted (.:format)
because there no :id
part.
Comments
Post a Comment