For some reason, in my function make_feed_preference
, the @user.feed_preference
never changes, even if I hard 开发者_StackOverflowcode it to @user.feed_preference = "foobar"
but it looks like redirect_to 'posts'
is working fine.
The bug is that the feed_preference
is always nil
even after the link_to
is pressed, so the (if feed_preference == nil
) is always true
. I still don't know what's causing this.
make_feed_preference
is stored in the users_controller. What it does is shows a news feed, but sorted according to a preference value (e.g., "time", "trending_value", "followers")
<%= link_to displayIcon(1), {:action => :make_feed_preference, :id => current_user.id, :preference => "trending value", :controller => "users"}, :method => :post %>
def make_feed_preference
@user = User.find(params[:id])
@user.feed_preference = params[:preference]
@user.save
redirect_to '/posts'
end
Note: i fixed it by attaching a new class to the users.
I would be using a conditional here:
redirect_to '/posts', :notice => if @user.save
'You have updated your feed preference.'
else
'Your input was invalid.'
end
You'll find that the @user validations are probably failing.
精彩评论