I have a function that does a partial render on my main page. The method works if called directly, from one of the links. The method is the following:
def show_card
@activity = Activity.find(params[:id])
respond_to do |format|
format.js
end
end
I need to call this method from another method, or at least render the same thing this method renders, but with different parameters. My second method is this :
def like_activity
@user = current_user
@activity = Activity.find(params[:id])
@user.like_activity!(@activity)
all = Activity.all
notWanted = Activity.where(id: Activity.joins(:memberships).where({ "memberships.user_id" => current_user.id})).or(Activity.where(id: Activity.joins(:likes).where({"likes.user_id" => current_user.id}).where.not("likes.user_likes_activity" => nil)))
queue = all - notWanted
nextActivity = queue.first()
redirect_to action: 'show_card', controller: 'pages', id:nextActivity.id
end
Basically, after you like an activity, the method should call the show_card and display the new activity. However, I'm getting the following error:
ActionController::UnknownFormat
While this is the output I get on the console :
> Redirected to http://localhost:3000/pages/show_card?id=88 Completed
> 302 Found in 99ms (ActiveRecord: 59.6ms)
>
>
> Started GET "/pages/show_card?id=88" for 127.0.0.1 at 2018-03-01
> 17:12:35 -0800 Processing by PagesController#show_card as HTML
> Parameters: {"id"=>"88"} User Load (6.5ms) SELECT "users".* FROM
> "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2
> [["id", 2], ["LIMIT", 1]] Activity Load (6.3ms) SELECT
> "activities".* FROM "activities" WHERE "activities"."id" = $1 LIMIT $2
> [["id", 88], ["LIMIT", 1]]
> Completed 401 Unauthorized in 23ms`
> (ActiveRecord: 12.8ms)
>
>
> ActionController::UnknownFormat (ActionController::UnknownFormat):
> app/controllers/pages_controller.rb:13:in `show_card'
I'm very confused on what am I missing. I'm also using Devise, I don't know if that might have to do with the 401 - Unauthorized. If you have any idea of what could be going on it would be really appreciated if you could let me know. Thanks!
Aucun commentaire:
Enregistrer un commentaire