重新向用户显示页面

时间:2016-12-21 03:30:50

标签: ruby-on-rails routes

当我在用户展示页面上创建活动时,如果确实正确提交,我希望它重定向回用户展示页面。无论如何我能做到这一点就是我的事件控制器:

class EventsController < ApplicationController
    def show
      @event = Event.find(params[:id])
      @songs = @event.songs.paginate(page: params[:page])
    end

    def create
        @event = current_user.events.build(event_params)
        if @event.save
            flash[:success] = "Event Created!"
            redirect_to 'user#show'
        else
            render 'welcome#index'
        end
    end

    def destroy
    end

    private 

      def event_params
        params.require(:event).permit(:name, :partycode)
      end
end

2 个答案:

答案 0 :(得分:1)

是的,你可以,但是你需要使用实际的路径,而不是redirect_to user_path(@event.user) 用户:

newtype Mu f = Roll { unroll :: f (Mu f) }

-- Replace all recursive constructors with r.
-- If any of them are nonregular (e.g. C3 :: Test Int -> Test a)
-- then this approach gets quite a bit more complicated, so I hope not.
data TestF a r where
  C1 :: Int -> a -> TestF a r
  C2 :: r -> r -> a -> TestF a r
  ...

-- This will take care of finding the recursive constructors
deriving instance Foldable (TestF a) 

-- This is your actual type (might want to wrap it in a newtype)
type Test a = Mu (TestF a)

foldMapRec :: (Foldable f, Monoid m) => (Mu f -> m) -> Mu f -> m
foldMapRec f (Roll a) = foldMap f a

答案 1 :(得分:1)

重定向到用户路径并传入用户ID。

SELECT
  meet_entries.id,
  member.firstname,
  member.surname,
  member.gender,
  member.dob,
  clubs.code,
  clubs.clubname,
  meet_entries.meals,
  meet_entries.massages,
  meet_entries.cost,
  meet_entries.cancelled,
  (SELECT meet_entry_status_codes.description
  FROM meet_entry_statuses, meet_entry_status_codes
  WHERE meet_entry_statuses.code = meet_entry_status_codes.id
  AND meet_entry_statuses.id = meet_entries.id
  ORDER BY meet_entry_statuses.id DESC
  LIMIT 1) as status,
  COUNT(DISTINCT meet_events_entries.id) as entries
FROM meet_entries, meet_events_entries, member, clubs, meet_entry_statuses, meet_entry_status_codes
WHERE meet_entries.meet_id = ?
  AND meet_entries.id = meet_events_entries.meet_entry_id
AND meet_entries.member_id = member.id
AND meet_entries.club_id = clubs.id
GROUP BY meet_entries.id
;