views:

28

answers:

1

I have a model User that has_one user_profile and a User_Profile belongs_to user

in the User controller I have:

  def personal
    @user = User.find_by_id(params[:id])
    @user_profile = @user.user_profile
    @user_profile ||= @user.build_user_profile
  end

  def update_personal
    @user = User.find_by_id(params[:id])
    if @user.user_profile.update_attributes(params[:user_profile])
      flash[:notice] = "OK"
      redirect_to @user
    else
      flash[:notice] = "Fail"
      render :action => 'update_personal'
    end
  end

In my personal.html.erb view I have:

<% semantic_form_for @user_profile, :url => { :action => "update_personal"} do |form| %>
  <%= form.inputs %>
  <%=  form.buttons %>
<%end%>

And on the rountes I have:

map.resources :users, :member => {
         :personal            => :get,
         :update_personal     => :put
        }

Now the strange thing is that I can do:

users/1/personal 

to see the form but when I submit I get this error:

Unknown action

No action responded to 1.

It's trying to find an action with the name 1.

Can anyone point me out on the right direction?

A: 

I just got the problem again, and finally understood the problem and found the solution.

This time i was using an ajax call using getJason. Because the call was a get, and in my routes I had a update_xxxxxx => :put, the route was ignored and the default :controller/:action/:id was used.

I just had to put the update_xxxx => :get and the problem was solved.

Maybe this will help someone.

Victor Martins